How do I validate the value of a textbox from 0000 thru 9999 on the server side via VB.NET?

I need to validate if a textbox's value is between 0000 thru 9999 (with padded zeroes).  I have to implement it on the server side using VB.NET code.

How can I do this?
crickpaoloAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TimCotteeHead of Software ServicesCommented:
Hello crickpaolo,

A regular expression of \d{4} will validate that easily, you can implement this as a regular expression validator client-side and then again server-side.

Regards,

TimCottee
  Imports System.Text.RegularExpressions 
Public Dim regex As Regex = New Regex( _
      "\d{4}", _
    RegexOptions.IgnoreCase _
    Or RegexOptions.CultureInvariant _
    Or RegexOptions.IgnorePatternWhitespace _
    Or RegexOptions.Compiled _
    ) 
Dim IsMatch As Boolean = regex.IsMatch(InputText)

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
crickpaoloAuthor Commented:
thanks man.
Anurag ThakurTechnical ManagerCommented:
make sure that your text box takes maximum input of 4 characters that also only numbers and no special characters alphabets and space or a dot
i will suggest you to do the first level of test by using a regularexpression validator then only verify again at the server side - why do you want to do a round trip for this kind of verification which can be easily done on the client side by regularexpression validator and the expression will be whats defined by TimCottee in the previous comment
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.