Created
March 31, 2016 15:00
-
-
Save xto3na/82c07dd42822dcd03be3b0c378d4041f to your computer and use it in GitHub Desktop.
Phone Input validate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Допустимые значения: цифры, пробелы, скобки, тире, количество допустимых символов: 1 - 20 символов. | |
Остальные символы не вводятся. | |
<input type="text" id="phone" placeholder="+38 (099) ___-__-__"> | |
<script> | |
document.addEventListener("DOMContentLoaded", function() { | |
$("#phone").keypress(function(eventObject) { | |
if (!(((eventObject.which >= 48) && | |
(eventObject.which <= 57)) | |
|| (eventObject.which == 32) | |
|| (eventObject.which == 45) | |
|| (eventObject.which == 40) | |
|| (eventObject.which == 41) | |
|| (eventObject.which == 43))) { | |
eventObject.preventDefault(); | |
} | |
var str = $("#phone").val(); | |
if (str.length >= 20) { | |
eventObject.preventDefault(); | |
} | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment