hello
i am using the bootstrap form validator for bootstrap.
i am having trouble understanding regexp
regexp: /^[a-z\s]+$/i,
this code will only allow the field to consist of alphabetical characters and spaces only.
can somebody break down each thing in there for me and separate what is what so i can learn how to change the variations and put new ones together. i tried googling regexp javascript and there is some information but its still also very confusing.
i am new to javascript.
thank you
regexp - form validation
Moderator: General Moderators
Re: regexp - form validation
This isn't even a Javascript question, but a regex one.
For the regular expression
/ is the pattern delimiter
^ denotes the beginning of a line, in the case of forms it would be the beginning of the value
[] denotes a range of characters. Anything within that range will be accepted.
a-z is just that, the letters a through z
\s indicates a space
+ indicates 1 or more occurrences
$ denotes the end of the line
i at the end means case insensitive.
For the regular expression
Code: Select all
/^[a-z\s]+$/i^ denotes the beginning of a line, in the case of forms it would be the beginning of the value
[] denotes a range of characters. Anything within that range will be accepted.
a-z is just that, the letters a through z
\s indicates a space
+ indicates 1 or more occurrences
$ denotes the end of the line
i at the end means case insensitive.