How to validate numeric string

P

Peter Afonin

Hello,

Should be a pretty simple question:

I need to validate a string. It must be numeric and contain exactly 12
characters. I know how to do it in code, but I'd like to use a validation
control. Should I use a Regular expression validator? What expression should
I use? I checked http://www.regxlib.com, but couldn't find exactly what I
need.

I would appreciate your help.

Thank you,
 
M

Matt Berther

Hello Peter,

Try

\d{12}

This should require exactly 12 numeric characters...
 
S

Scott M.

Use a RegularExpression Validator. You didn't tell us what your numeric
format is though, so we can't suggest a pattern.
 
P

Peter Afonin

Thank you, Scott.

Any numbers, exactly 12 digits: 273861129372, for example. No other
characters, like "." or "," or "-".

Peter

Scott M. said:
Use a RegularExpression Validator. You didn't tell us what your numeric
format is though, so we can't suggest a pattern.
 
S

Scott M.

\d{12}



Peter Afonin said:
Thank you, Scott.

Any numbers, exactly 12 digits: 273861129372, for example. No other
characters, like "." or "," or "-".

Peter
 
S

Scott Mitchell [MVP]

Also remember that the RegularExpressionValidator does not *require*
that a value be present, so if you want to force this you must, in
addition, use a RequiredFieldValidator.


--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top