Sunday, 15 August 2010

javascript - IP masking HTML input form with jQuery -



javascript - IP masking HTML input form with jQuery -

so need validate input field take ip addresses.

<form method="post"> <input type='text' placeholder='xxx.xxx.xxx.xxx' name='ip'> </form>

since there no ip value attribute type, need validate using javascript or client-sided language. i've reached jquery snippet using mask library.

jquery(function($){ $("input").mask("9?99.9?99.9?99.9?99", {placeholder:" "}); });

this doesn't work on side. here how include scripts (just point out).

<script src="http://code.jquery.com/jquery-1.11.0.min.js" type="text/javascript"></script> <script src="https://raw.githubusercontent.com/digitalbush/jquery.maskedinput/1.3.1/dist/jquery.maskedinput.js" type="text/javascript"></script>

also, if manage create work, still isn't best alternative since two-digit parts of ip address won't rendered (i.e. 84.55.11.499). questions are:

why above code not work on end on jsfiddle? how filter two-digit ip addresses mask library?

i see you're using jquery plugin - seek 1 has working ip mask

this plugin here

it's done this:

$('.ip_address').mask('0zz.0zz.0zz.0zz', {translation: {'z': {pattern: /[0-9]/, optional: true}}});

or identical - little shorter:

$('.ip_address').mask('099.099.099.099');

the lastly illustration lastly line used in fiddle example

according jquery mask docs :

0: numbers.

9: numbers optional.

so see - 099.099.099.099, if wanted forcefulness 2 digits in between each decimal 009.009.009.009

javascript jquery html masking

No comments:

Post a Comment