Logo 
Search:

Asp.net Forum

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

Validator(s)

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

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.

20.20.30.X

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

Share: 

 

5 Answers Found

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

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


^20\.20\.30\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$

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

A RegEx Validator see:


docs.aspng.com/.../webvalidation.aspx#regex

The expression you want is:

^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$

(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

20.20.30.1

20.20.30.3

20.20.30.4

20.20.20.1

20.20.20.2

20.20.20.6

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:

^20.20.30.\d{1,3}$

To learn more about regular expressions, check out the articles at:
www.4guysfromrolla.com/.../...larExpressions.shtml

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

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




Tagged: