validating space in alphanumeric string thru regular expression
I am using the following regular expression
"[a-zA-Z0-9 \s]{4,}"
to validate an alphanumeric entry with space and minimum length 4. but it doesn't accept spaces. what a开发者_运维知识库m i missing here.
This reference over here, under flag options says:
x
If set, allow use of white space and #comments within patterns
It sounds like you need to set this x
flag option for whitespace to work. If I understand it correctly, your regex should look something like
"(?x)[a-zA-Z0-9 \s]{4,}"
精彩评论