简体   繁体   中英

Regex allowing 3 numbers with no special characters and space

I am using a regex as /^-?(?:\\d+|\\d{1,3}(?:,\\d{3})+)?$/ which allow only 3 numbers and no special characters

I need to include space check as well. Please help me

I don't know why your regular expression is so complex. If you need three digits with no other characters, just use this:

/^[0-9]{3}$/

That will only validate strings that are three digits with nothing else, "324", "857", "111". You get it.

If you have other requirements, please update your question with them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM