I'm looking at using jQuery to validate IP address on a webpage. I can get two help.
- How can I get the page to appear
valid IP
andinvalid IP
, just when the page loads the text box Is not edited. - How can I style text so that
valid IP
appears in green andinvalid IP
appears in red?
I have created.
- When the text box is edited, just when the page loads So how can I get a valid IP and invalid IP?
You can wait until Dom-tree is loaded and after that the IP receives and verifies:
$ (Document) .on ("ready", function () {var ip = getIp (); // the way you apply it. ValidateIpAddress (ip);});
Where your valid IP address
changes the method text whether the pattern is valid:
if (! Test! IP)) {$ ('# valid' _ip '). Text ('Not valid IP'); } And {$ ('# valid' _ip '). Text ('valid IP'); }
- How can I create text so that the legitimate IP appears in green and the invalid IP appears in red?
Create a CSS file that includes sections
. Valid {color: # 00ff00; / * Green * /. Native (color: # FF0000; / * Red * /}
Then you can simply add classes with jQuery:
if (! Pattern.test (ip)) {$ ('#validate_ip'). Text ('Not valid IP'); $ ('# Validate_ip') addClass ('legal'). } And {$ ('# valid' _ip '). Text ('valid IP'); $ ('# Validate_ip') addClass ('Invalid') }
Comments
Post a Comment