So I need to validate an input field to accept IP addresses.
<form method="POST">
<input type='text' placeholder='xxx.xxx.xxx.xxx' name='IP'>
</form>
Since there is no IP value for the attribute type, I would need to validate it using Javascript or some client-sided language. I've reached to this jQuery snippet using a mask library.
jQuery(function($){
$("input").mask("9?99.9?99.9?99.9?99", {placeholder:" "});
});
This however doesn't work on my side. Here is how I include the scripts (just to 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, even if I manage to make this work, it still isn't the best option since two-digit parts of an IP address won't be rendered properly (i.e. 84.55.11.499). So my questions are:
- Why does the above code not work on my end but does on JSFiddle?
- How do I filter two-digit IP addresses with the mask library?