admin管理员组文章数量:1390491
Can any one give the perfect regular expression for
1. US date format (mm/dd/yyyy).
2. Alpha Numerics.
3. Alpha Numerics with spaces.
4. age betwenn 15-100.
in java script. i have this Regex.
/^[0-9a-zA-Z]+$/ (alphanumeric that doesnot allow spaces)
/^[0-9]+$/ ( for age but not getting below 100)
/^(0[1-9]|1[012])[-/.](0[1-9]|[12][0-9]|3[01])[-/.](19|20)\d\d+$/; (US date format)
Thanks
Can any one give the perfect regular expression for
1. US date format (mm/dd/yyyy).
2. Alpha Numerics.
3. Alpha Numerics with spaces.
4. age betwenn 15-100.
in java script. i have this Regex.
/^[0-9a-zA-Z]+$/ (alphanumeric that doesnot allow spaces)
/^[0-9]+$/ ( for age but not getting below 100)
/^(0[1-9]|1[012])[-/.](0[1-9]|[12][0-9]|3[01])[-/.](19|20)\d\d+$/; (US date format)
Thanks
Share Improve this question edited Aug 23, 2011 at 11:28 Chakradhar asked Aug 23, 2011 at 8:41 ChakradharChakradhar 7736 gold badges14 silver badges29 bronze badges 1- gskinner./RegExr I would try to write some for you but they would catch that I am that weird VIM guy. – James Andino Commented Aug 23, 2011 at 11:24
2 Answers
Reset to default 2- I'm guessing you dont want the brackets
(0[1-9]|1[0-2])/(0[1-9]|1[0-9]|2[0-9]|3[01])/[0-9]{4}
Note this doesn't validate that the number of days is valid in that month
[a-zA-Z0-9]+?
[a-zA-Z0-9\s]+?
- I wouldn't use regex for this but anyway
(1[5-9]|[2-9][0-9]|100)
for these you may need to add the bol an eol chars depending on where your input is ing from (as in is there other content in the line).
Tested using regexpal
I think http://regexpal./ is a very good resource to learn regexp in general. Combine this with the mozilla docs: https://developer.mozilla/en/JavaScript/Guide/Regular_Expressions
For 4, you are better of parsing the string as a number with parseInt
or parseFloat
and then paring them with an if
.
本文标签: regexBasic RegExp examples in JavascriptStack Overflow
版权声明:本文标题:regex - Basic RegExp examples in Javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744660908a2618241.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论