0

I am writing an application which involves users entering in IP addresses in the following format: "198.109.234.250"

I am using an ajax control at the minute that creates the mask like this: _ _ . _ . _ . _ _ which is fine because it will not allow letters to be entered just numbers.

Here is my question:

How do i set the maximum value for each three digit section of the I.P? like so that the maximum for each section can only be 250? like this: 250.250.250.250

I have been looking for an attribute within the ajax extender but cant seem to find one.

1
  • Which control are you using? Commented Aug 13, 2013 at 18:59

1 Answer 1

2

I'm not a regular expression expert, but you can use RegularExpressionValidator for validating IP Address.

For example,

<asp:TextBox runat="server" ID="IPAddressTextBox" />
<asp:RegularExpressionValidator 
    ID="RegularExpressionValidator1" 
    runat="server"
    ValidationExpression="\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b"
    ControlToValidate="IPAddressTextBox" 
    Text="IP Address must in format - 255.255.255.255"
    Display="Dynamic" />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.