admin管理员组文章数量:1130349
I am not good with regular expression patterns. I have to put a validation on an string, to allow
only alphabets, numbers, decimals, spaces, ma and underscore
for allowing the alphabets and spaces I have /^[a-zA-Z][a-zA-Z\\s]+$/
Please help me in creating all the above conditions in one pattern.
Thanks
I am not good with regular expression patterns. I have to put a validation on an string, to allow
only alphabets, numbers, decimals, spaces, ma and underscore
for allowing the alphabets and spaces I have /^[a-zA-Z][a-zA-Z\\s]+$/
Please help me in creating all the above conditions in one pattern.
Thanks
Share Improve this question edited Dec 29, 2012 at 20:57 Sashi Kant asked Dec 26, 2012 at 13:30 Sashi KantSashi Kant 13.5k9 gold badges49 silver badges71 bronze badges 2- Not sure why you added a jQuery tag... And what is the difference between numbers and decimals. – PhiLho Commented Dec 26, 2012 at 13:34
- Is "decimals" the decimal point? I added it, just in case. – PhiLho Commented Dec 26, 2012 at 13:37
3 Answers
Reset to default 8this regex should work for your requirements
'[a-zA-Z0-9_. ,]*'
In the regex, I specified the range a to z, A to Z (uppercase), 0 to 9 and the single character _, decimal point ".", space and a ma.
If you want to make sure you want at least one character after the first letter, you can replace the * with a +, or {2,} with at least 2 more characters, or {2,5} with between 2 and 5 characters.
You can try:
/^[\w., ]+$/
I don't know what are the requirements for the starting char, if there are any.
Rahul's answer gave me the direction to think, but for the visitors, may be this too can be helpfull
patternForClasName = /^([a-zA-Z0-9 _]+\.)*[a-zA-Z0-9 _]+$/;
// Allowing valid className which has a format abcsasa.dsd.dsd(the class or a package name can have an underscore or a numerical)
patternForName = /^([a-zA-Z0-9 _-]+)$/;
// Allowing alphanumeric + spaces + (_)underscore and a (-)dash
patternForDescription = /^([a-zA-Z0-9 _-]+[\,\.]+)*[a-zA-Z0-9 _-]*$/;
// Allowing alphanumeric,spaces, (_)underscore, (-)dash, ma, decimal
patternURLFormat = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
// For a valid URL
I am not good with regular expression patterns. I have to put a validation on an string, to allow
only alphabets, numbers, decimals, spaces, ma and underscore
for allowing the alphabets and spaces I have /^[a-zA-Z][a-zA-Z\\s]+$/
Please help me in creating all the above conditions in one pattern.
Thanks
I am not good with regular expression patterns. I have to put a validation on an string, to allow
only alphabets, numbers, decimals, spaces, ma and underscore
for allowing the alphabets and spaces I have /^[a-zA-Z][a-zA-Z\\s]+$/
Please help me in creating all the above conditions in one pattern.
Thanks
Share Improve this question edited Dec 29, 2012 at 20:57 Sashi Kant asked Dec 26, 2012 at 13:30 Sashi KantSashi Kant 13.5k9 gold badges49 silver badges71 bronze badges 2- Not sure why you added a jQuery tag... And what is the difference between numbers and decimals. – PhiLho Commented Dec 26, 2012 at 13:34
- Is "decimals" the decimal point? I added it, just in case. – PhiLho Commented Dec 26, 2012 at 13:37
3 Answers
Reset to default 8this regex should work for your requirements
'[a-zA-Z0-9_. ,]*'
In the regex, I specified the range a to z, A to Z (uppercase), 0 to 9 and the single character _, decimal point ".", space and a ma.
If you want to make sure you want at least one character after the first letter, you can replace the * with a +, or {2,} with at least 2 more characters, or {2,5} with between 2 and 5 characters.
You can try:
/^[\w., ]+$/
I don't know what are the requirements for the starting char, if there are any.
Rahul's answer gave me the direction to think, but for the visitors, may be this too can be helpfull
patternForClasName = /^([a-zA-Z0-9 _]+\.)*[a-zA-Z0-9 _]+$/;
// Allowing valid className which has a format abcsasa.dsd.dsd(the class or a package name can have an underscore or a numerical)
patternForName = /^([a-zA-Z0-9 _-]+)$/;
// Allowing alphanumeric + spaces + (_)underscore and a (-)dash
patternForDescription = /^([a-zA-Z0-9 _-]+[\,\.]+)*[a-zA-Z0-9 _-]*$/;
// Allowing alphanumeric,spaces, (_)underscore, (-)dash, ma, decimal
patternURLFormat = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
// For a valid URL
本文标签:
版权声明:本文标题:c# - Regex pattern allowing alphabets, numbers, decimals, spaces and underscore - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1740190145a1727885.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论