[英]Regular expression to validate the user input
I want a regular expression, which should start with alphabet or numbers and followed by alphanumeric character and in between, it may or may not contain forward or backward slash ( \\,/
). 我想要一个正则表达式,它应该以字母或数字开头,后跟字母数字字符,并且介于两者之间,它可以包含也可以不包含正斜杠( \\,/
)。
Highly appreciate your help. 非常感谢您的帮助。
Thanks :) 谢谢 :)
/^[a-z0-9][\w\\\/]+$/i
^
). 行首( ^
)。 [a-z0-9]
- a letter or number - 1 occurrence [a-z0-9]
-一个字母或数字-1次出现 [\\w\\\\\\/]+
- multiple occurrences of alphanumeric characters (including _
) or \\
or /
. [\\w\\\\\\/]+
-多次出现的字母数字字符(包括_
)或\\
或/
。 $
). 行尾( $
)。 i
gnore-case flag will accept both uppercase and lowercase. i
忽略大小写标志将接受大写和小写。
[xyz]
specifies a character class meaning that either x
or y
or z
can be matched. [xyz]
指定一个字符类,表示可以匹配x
或y
或z
。
If you don't consider 123_asd
to be alpha-numeric, use: 如果您不认为123_asd
是字母数字,请使用:
/^[a-z0-9][a-z0-9\\\/]+$/i
Hope it helps! 希望能帮助到你!
^[a-zA-Z0-9]+[a-zA-Z0-9\/\\]*
This will accept / or \\ only in between. 这仅在两者之间接受/或\\。
Edit: Oops:p Missed the numbers, updated. 编辑:糟糕:p缺少数字,已更新。 Thanks for pointing out. 感谢您指出。
Try this regex: 试试这个正则表达式:
(?i)^[a-z\d][a-z\d\\/]*$
?i
treats upper-case letters as lower-case letters. ?i
将大写字母视为小写字母。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.