Skip to content

Instantly share code, notes, and snippets.

@abhishek-9ithub
Created November 25, 2017 09:35
Show Gist options
  • Save abhishek-9ithub/c42606fd9b412d7630eca116e9e6e30c to your computer and use it in GitHub Desktop.
Save abhishek-9ithub/c42606fd9b412d7630eca116e9e6e30c to your computer and use it in GitHub Desktop.
mobile number verification script
<!DOCTYPE html>
<head>
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
</head>
<body>
<input type="text" maxlength="10" class="mobileNum">
<a href="javascript:void(0)">Click ME</a>
<span class="error" style="color:red;">M</span>
</body>
<script>
$(function() {
pattern = /^[789]\d{9}$/;
$('.mobileNum').keydown(function(e) {
-1 !== $.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) || /65|67|86|88/.test(e.keyCode) && (!0 === e.ctrlKey || !0 === e.metaKey) || 35 <=
e.keyCode && 40 >= e.keyCode || (e.shiftKey || 48 > e.keyCode || 57 <
e.keyCode) && (96 > e.keyCode || 105 <
e.keyCode) && e.preventDefault();
});
$('.mobileNum').focusout(function() {
if (this.value.length < 10) {
$('.error').text('Please check your input')
} else {
$('.error').text('Correct Mobile Number')
}
});
})
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment