I need a regular field validator that accepts alphabet numbers `-. and only one space between words
4 answers
Your curly braces have space in them and are also at the beginning of your regex, after the carrot. so you need to exclude spaces at the beginning and end of the text:
/^([a-z0-9\-]+\s{0,1}[a-z0-9\-]+)+$/gmi
you also want to include the '-' character by escaping and including in it.
A good site for testing regular expressions
+1
source to share
This needs to do a pretty good job:
/*#!(?#!js valid Rev:20150715_1300)
# Validate alphabets numbers `-. and only one space.
^ # Anchor to start of string.
(?=[^ ]+(?:[ ][^ ]+)*$) # Only one space between words.
[a-zA-Z0-9 `.-]* # One or more allowed chars.
$ # Anchor to end of string.
!#*/
var valid = /^(?=[^ ]+(?: [^ ]+)*$)[a-zA-Z0-9 `.-]*$/;
+1
source to share