-6

I need a bit of help here I need a perfect satisfying regexp for all indian phone numbers at current a regexp which will validate every indian phone number.

function checkemailandphone() {
    var emailandphone = document.getElementById("emailandphone").value;

    var email = /[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$/g;

    var phone = /^[6-9]\d{9}$/g;

    if(emailandphone.match(email)) {
       if(emailandphone){
            $.ajax({
                type: 'post',
                url: 'emailcheck.php',
                data: {
                email:emailandphone,
                },
                success: function (response) {
                    if(response == "OK"){
                        $("#email").css({'background-color': 'lightgreen'});
                        var emailandphonevalid = true;
                    } else {
                        $("#email").css({'background-color': 'lightgray'});
                        var emailandphonevalid = false;
                    }
                }
            });
        } 
    } else if(emailandphone.match(phone)) {
        if(emailandphone){
            $.ajax({
                type: 'post',
                url: 'phonecheck.php',
                data: {
                phone:emailandphone,
                },
                success: function (response) {
                    if(response == "OK"){
                        $("#email").css({'background-color': 'lightgreen'});
                        var emailandphonevalid = true;
                    } else {
                        $("#email").css({'background-color': 'lightgray'});
                        var emailandphonevalid = false;
                    }
                }
            });
        }
    } else {
        $("#email").css({'background-color': 'lightgray'});
        var emailandphonevalid = false;
    }
}

The reason is quite weird but i need a code such that if a user gives input which has +91 added the expression must ignore it cause its already indian number basically there must be no errors in validation.

jww
  • 97,681
  • 90
  • 411
  • 885
vinayak
  • 3
  • 6
  • Before I close this as a dupe, is there any reason why [this solution](https://stackoverflow.com/questions/3813195/regular-expression-for-indian-mobile-numbers) won't work for you? – Rory McCrossan Nov 30 '18 at 11:29
  • Possible duplicate of [regular expression for Indian mobile numbers](https://stackoverflow.com/questions/3813195/regular-expression-for-indian-mobile-numbers) – ElusiveCoder Nov 30 '18 at 11:31
  • the reason is quite weird but i need a code such that if a user gives input which has +91 added the expression must ignore it cause its already indian number basically there must be no errors in validation – vinayak Nov 30 '18 at 11:34
  • Show us the effort you did for it. show us minimal examples and code – Code Maniac Nov 30 '18 at 11:38

1 Answers1

1

In javascript you can try to use this regexp

/\+91[0-9]{10}/