2016-09-25 45 views
0
<form action=demo.php method="post"> 
<div > 
     <label class="control-label" for="email">Your email address/Mobile number</label> 
     <div class="controls"> 
      <input type="email" name="email" required /> 

     </div> 
    </div> 

    <input type="submit" name="submit">Submit</button> 
</form> 

我想通过PHP验证验证电子邮件或手机与单个输入和移动预浸开始只有7,8 & 9,只应该是10位。 我如何验证这只在PHP中。电子邮件和手机号码验证使用PHP

+0

检查这两个:http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address?rq=1和http://stackoverflow.com/questions/123559/a-comprehensive-regex-for-phone-number-validation?rq = 1 – ihemant360

+0

这些链接没有解决我的查询我想混合正则表达式的单个输入,其中单个正则表达式可以找出有效的电子邮件或有效的移动 – Amy

回答

0

对于JavaScript

function validateEmail() { 
    var email = document.getElementById('txtEmail'); 
    var mailFormat = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})|([0-9]{10})+$/; 
    if (email.value == "") { 
     alert(" Please enter your Email or Phone Number "); 
    } 
    else if (!mailFormat.test(email.value)) { 
     alert(" Email Address/Phone number is not valid, Please provide a valid Email or phone number "); 
     return false; 
    } 
    else { 
     alert(" Success "); 
    } 
} 

使用与节点JS

/^([_a-z0-9]+(.[_a-z0-9]+)这个正则表达式@ [A-Z0-9 - ] + -)([A-Z0-9] +)。([AZ] {2,5-})|(\ d +)$/

Demo

+0

请改变这个正则表达式 /^([a-a-z0-9]+(.[_a-z0-9]+)@[a-z0-9-]+(.[a-z0-9-]+)(..[az ] {2,5}))|(\ d + $)$/ 到10位手机号码,从7,8,9开始 – Amy