jquery - HTML Form IP Address Validation -


I'm looking at using jQuery to validate IP address on a webpage. I can get two help.

  1. How can I get the page to appear valid IP and invalid IP , just when the page loads the text box Is not edited.
  2. How can I style text so that valid IP appears in green and invalid IP appears in red?

I have created.

  1. 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'); }  
  1. 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