regExpression Help

  • Thread starter Thread starter jeffery.kabir
  • Start date Start date
J

jeffery.kabir

I'm trying to get a regular expression that matches only 4 digits, i'm
using

Regex.IsMatch(userID, "^\d{4}")

If the user types in more than 4 digits it still is being returned as a
match. Should I be using IsMatch, or is my regular expression wrong?
Thanks.
 
I'm trying to get a regular expression that matches only 4 digits, i'm
using

Regex.IsMatch(userID, "^\d{4}")

If the user types in more than 4 digits it still is being returned as a
match. Should I be using IsMatch, or is my regular expression wrong?
Thanks.

Try
Regex.IsMatch(userID, "^\d{4}$")
 
Try "^\d{4}$"

I'm trying to get a regular expression that matches only 4 digits, i'm
using

Regex.IsMatch(userID, "^\d{4}")

If the user types in more than 4 digits it still is being returned as a
match. Should I be using IsMatch, or is my regular expression wrong?
Thanks.
 
I'm trying to get a regular expression that matches only 4 digits, i'm
using

Regex.IsMatch(userID, "^\d{4}")

If the user types in more than 4 digits it still is being returned as a
match. Should I be using IsMatch, or is my regular expression wrong?
Thanks.
Try "^\d{4}\z". I think you are forgetting to check for the end of the
string.

jjrdk
 

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

Back
Top