![Number Number](/uploads/1/2/4/7/124794771/706203659.png)
My school started using digits before 2014. Digits on SuccessNet Plus. My school just started using digits in 2014. Digits on Realize. In the airstream to apply applied science, NADRA has hit another achievement with the launch of a one and the same valuable service for verifying CNIC details. Forthwith you don’t need to visit NADRA business office. to baffle someone’s details verified. Whether it’s part of desktop ascertains for employing or any other purpose, verifying someone’s.
This question already has an answer here:
- Regex for numbers only 17 answers
I need a regex that will accept only digits from 0-9 and nothing else. No letters, no characters.
I thought this would work:
or even
but these are accepting the characters : ^,$,(,), etc
I thought that both the regexes above would do the trick and I'm not sure why its accepting those characters.
EDIT:
This is exactly what I am doing:
This is allowing the characters I mentioned above.
mo alaz
mo alazmo alaz
marked as duplicate by Michael Liu, Gert Arnold, Soner Gönül, csl, KrishnabhadraNov 1 '13 at 8:53
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1 Answer
Your regex
^[0-9]
matches anything beginning with a digit, including strings like '1A'. To avoid a partial match, append a $
to the end:This accepts any number of digits, including none. To accept one or more digits, change the
*
to +
. To accept exactly one digit, just remove the *
.UPDATE: You mixed up the arguments to
IsMatch
. The pattern should be the second argument, not the first:CAUTION: In JavaScript,
d
is equivalent to [0-9]
, but in .NET, d
by default matches any Unicode decimal digit, including exotic fare like ႒ (Myanmar 2) and ߉ (N'Ko 9). Unless your app is prepared to deal with these characters, stick with [0-9]
(or supply the RegexOptions.ECMAScript flag).Michael LiuMichael Liu