Phone Number Validation. Allow only 0 as first digit

Jackson

i have a phone number validation where only numbers are allowed on keypress and first number should be 0. this is my jquery script:

jQuery("#phone-number").keypress(function(ev){
    var x = document.getElementById("phone-number").value;
    // Don't ignore numbers.
    if ((ev.charCode >= 64 && ev.charCode <= 91) || (ev.charCode >= 96 && ev.charCode <= 123) && x.charAt(0)!="0" ) {
                alert("it should start with 0 ");
                return false;
    }

});

x.charAt(0)!="0" is not working as any number can be passed as 1st digit.

Saurabh Mistry

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="phone-number"/>
$(document).on('input','#phone-number',function(){
    var phone=$('#phone-number').val();
   if(phone.indexOf('0')!==0){
     alert('First number must be 0');
     $('#phone-number').val('');
   }
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Email and phone Number Validation in android

From Dev

How to allow the first digit in EditText to be a zero (Android)

From Dev

Phone Number, Validation, and Dwolla

From Dev

Validating 7 digit phone number

From Dev

Converting a letter to a digit for phone number in Python

From Dev

phone number validation in check_phone function

From Dev

phone Number validation in java

From Dev

Phone Number Validation MVC

From Dev

round number to the first 3 digits (start with digit != 0)

From Dev

Phone number validation with jQuery

From Dev

Phone number regex validation

From Dev

phone number validation regex in rails

From Dev

Regex to allow only 10 or 16 digit comma separated number

From Dev

jQuery Validation Phone Number Prefix

From Dev

Match only first occurrence of digit

From Dev

Allow only one Digit in Jquery

From Dev

number reversal program gives only the first digit in output instead of the whole number

From Dev

PHP - basic phone number validation

From Dev

Validation for phone number in iOS

From Dev

phone number validation that accept only + and - signs

From Dev

Regex for phone number validation

From Dev

Regex to allow only numbers and +, -, () for number phone

From Dev

Sorting by first digit not whole number

From Dev

Phone number validation html form

From Dev

Phone number Validation in C

From Dev

Validation with total 4 digit and only 2 digit after decimal

From Dev

Broken Phone Number Validation

From Dev

Chrome Autocomplete only fills first 3 numbers of a phone number

From Dev

Custom validation for phone number in JS