Logo 
Search:

Asp.net Answers

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds
  Question Asked By: Fahimah Khan   on Dec 21 In Asp.net Category.

  
Question Answered By: Jonah Brown   on Dec 21

You've gotten a lot of answers and I think they've all been close.
Let me try to answer all of your questions:

Can you use a regular expression to validate:
20.20.20.X and 20.20.30.X

Yes, of course. I suggest it isn't worth doing, but it is possible
to do. I would take the following approach and use a custom
validator.

The first part of the expression is simple because you have two fixed
sets of networks: 20.20.30 and 20.20.20

I would still do this with a regular expression:
20\.20\.[23]0\.(\d){1,3}

20\.20\.[23]0\. this will match either 20.20.30 or 20.20.20

The (\d){1,3} will match any 1-3 digit number. I suggest a custom
validator to use that match ($1) and make sure 0 < $1 < 256 (make
sure it's in the valid range for an IP.

You could do it with a regular expression, it would look pretty
obnoxious. I say use tools where they make sense (like IsDate()
instead of a 4 line regular expression to validate  date...). Plus I
think this way will make more sense in the long run when you or
someone else is looking back on your code.

Share: