At the time of given the input in edittext field it show error if anyone will put incorrent IP Address format of IP adsress should be like these 000.000.0.000 plz help me out
IN HTML5:-
<div data-role="content">
<form id="form">
<div data-role="fieldcontain">
<label for="ip">IP Address/System Name</label>
<input name="ip" id="ip" type="text" pattern="((^|\.)((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]?\d))){4}$">
</div>
<div style="text-align:center;">
<div data-role="button" data-theme="b" data-inline="true" id="button1">Update</div>
</div>
</div>
Basic Validation − First of all, the form must be checked to make sure all the mandatory fields are filled in. It would require just a loop through each field in the form and check for data. Data Format Validation − Secondly, the data that is entered must be checked for correct form and value.
Using the email type, we can check the validity of the form field with a javascript function called… checkValidity() . This function returns a true|false value. checkValidity() will look at the input type as well as if the required attribute was set and any pattern="" tag .
Pattern validation is achieved using regular expressions, which is a string of characters and symbols that defines a search pattern. For example, let's say you have an Input element where you want users to enter a username.
For HTML5 validation to work on submit, You have to put required
attribute in your input
fields, you want to validate using HTML5 and you have to submit the form.
You can handle the form data submitted through javascript, and incase you do want to handle the submitted data manually then you have to specify data-ajax="false"
in you form
tag
For your code, try this
<div data-role="content">
<form id="form" data-ajax="false">
<div data-role="fieldcontain">
<label for="ip">IP Address/System Name</label>
<input name="ip" id="ip" type="text" required pattern="((^|\.)((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]?\d))){4}$">
</div>
<div style="text-align:center;">
<input type="submit" value="Submit button" />
</div>
</form>
</div>
And in javascript you can do something like
$("#form").submit(function(e){
e.preventDefault();
//call your method
});
One route you can go uses mask.js - In your case you can have it force the user to input their data in the proper format, pre-populate the '.' characters in the IP, and stop the user from entering non-numeric values.
Mask.js
And here is a fiddle - http://jsfiddle.net/QF9Lz/2/
click in the textbox, you'll see a formatting mask appear and you will only be able to enter numeric values in the format you specified.
So, once you include mask.js in the head, you can initialize the input mask like this:
$(document).ready( function() {
$('#ip').mask('999.999.9.999');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With