Archive for February 7th, 2008|Daily archive page
A4: the validation of only numbers and letters
around 7pm, wed, 2/6/08,
i finished it. it was so relatively easy… but as always, you just need to be in the know.
it was a little hairy but an example of the code i ended up with was:
if((textfields.city.value == “”)||(!(textfields.city.value.match(/^[a-zA-Z]+$/))) ) {
if statement says: if the value entered for the city is empty OR if the value entered does NOT match a lower or upper case letter, then it will return the alert box: “Please enter your city” and not continue the process.
the regular expression, as it is called, is: /^[a-zA-Z]+$/
the backslashes “/” enclose the regular expression,
the “^” indicates the beginning of the expression,
the “[ ]” show what the range of allowed characters are which are-
lower and upper case letters,
the “$” means the end of the expression.
i’m not too sure what the “+” sign is for…
i still wasn’t able to figure out how to allow spaces within the user input.
but yeah… that was all i really needed to figure out so i must say that this assignment was done faster than normal. especially because erik helped me out a LOT. but i think i learned from it as well and i know that this stuff will be useful.
the only thing that really frustrates me is the divide between common laymen users and hardcore life-long programmers. little things like the regular expression have absolutely no learning curve. you either know about it or you don’t. there’s no way to really know about it unless you stumble across it online or if someone flat-out tells you. perhaps that’s something programmers really need to develop. i know that javascript and other stuff are very people-friendly with normal language but it’s still a bit of an alien language.
Leave a Comment