-
Javascript grr!
Hi, having loads of trouble with some javascript validation, nothing seems to be working for me!
This is what has been set out as to what has to be done:
- the length of the input is bigger than 0 but not greator than 14
- only letters a-z "-" and space
- the "-" and space must be entered
- the "-" or space must not be either the first or last letter entered
- "-" must not be the immediate neighbour to a space
- "-" or space must not be adjacent
the data is entered through a normal textfield.
Any help would be greatly appreciated
Thanks for your help :)
-
Write a function to do the checks returning a boolean value to say if it's passed or not. Find the "-" if charAt(indexHere + 1) == a space then say no ;) Pretty straight forward tbh. Think of it logically, break the task down into smaller tasks, what would you need to check etc?
I'd loop through all the characters to check they're valid creating a function to return a boolean value dependant on if they're part of the alphabet, a "-" or a space.
EDIT: Sounds similar to a module i studied with the OU a year ago, what's it for?
-
do a look for regular expressions..
then I'd loop through as Kezzer mentions checking each requirement :)
-
I was going to say regex but i didn't know if they existed in JavaScript ;) Plus, i've never really touched regex
-
Well, it's what regex was designed to do ;)
-
cheers for the help guys, just had a look at a load of regexp stuff and it seems to be the way forward. Really struggling to get my head round comining all of the necessary expressions though!
I've had alook at a few websites which were ok but nothing expecially helpful for the complete beginner, do you know of any good guides?
Thanks for your help :)
-
hopefully this should be of some help.. http://www.webreference.com/js/column5/
-
yeah thats one of the websites i found first off, quite helpful, its just the operations of finding which chracters are next to which that i'm having trouble with