【问题标题】:Regexp for all Indian phone numbers in 2018 [closed]2018 年所有印度电话号码的正则表达式 [关闭]
【发布时间】:2019-05-02 13:22:13
【问题描述】:

我在这里需要一点帮助

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;
    }
}

原因很奇怪,但我需要一个代码,这样如果用户提供的输入添加了 +91,则表达式必须忽略它,因为它已经是印度数字,因此验证中必须没有错误。

【问题讨论】:

  • 在我作为一个骗子关闭它之前,this solution 有什么理由不适合你吗?
  • 原因很奇怪,但我需要一个代码,这样如果用户提供的输入添加了 +91,则表达式必须忽略它,因为它已经是印度数字,基本上必须没有验证错误跨度>
  • 向我们展示您为此付出的努力。向我们展示最少的示例和代码

标签: javascript jquery regex web backend


【解决方案1】:

在javascript中你可以尝试使用这个正则表达式

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

【讨论】:

  • 感谢您的帮助
猜你喜欢
  • 2012-03-24
  • 1970-01-01
  • 1970-01-01
  • 2012-12-15
  • 1970-01-01
  • 1970-01-01
  • 2013-08-23
  • 1970-01-01
  • 2017-09-23
相关资源
最近更新 更多