Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds


  Asked By: Fahimah    Date: Dec 21    Category: Asp.net    Views: 529

Just to see which ways you all would do this, I have a text box in a data grid when in edit mode. Now that text box will always display an IP address, i.e.


Now the only variable that will change is X, how and which validator would you all use to validate this information?



5 Answers Found

Answer #1    Answered By: Olivia Campbell     Answered On: Dec 21

use the regular expression validator. The validation expression would be:


Answer #2    Answered By: Hariz Burki     Answered On: Dec 21

A RegEx Validator see:


The expression you want is:


(obtained from RegEx lib a place with a ton of pre-made Regexs (although not all are perfectly tested, this one is good)

Answer #3    Answered By: Bien Nguyen     Answered On: Dec 21

With the Rehex can you allow two dff values i.e.

A ip addy 20.20.30.x and allow 20.20.20.X ?

Is that possible cause in that col I have values like the following

I need to validate  both the 20.20.30.x and the 20.20.20.x

Any ideas?

Answer #4    Answered By: Freddie Evans     Answered On: Dec 21

You could use a RegularExpressionValidator with a ValidationExpression of:


To learn more about regular expressions, check out the articles at:

Answer #5    Answered By: Jonah Brown     Answered 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

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\. 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.

Didn't find what you were looking for? Find more on Validator(s) Or get search suggestion and latest updates.