开发者

validating space in alphanumeric string thru regular expression

开发者 https://www.devze.com 2023-03-16 05:52 出处:网络
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 mis

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,}"
0

精彩评论

暂无评论...
验证码 换一张
取 消