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>

I want to validate Email or Mobile via PHP validation with preg with single input and Mobile starts only 7,8 & 9 and only should be 10 digit. How can i validate this only in PHP.

Amy
  • 161
  • 1
  • 10
  • check this two : http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address?rq=1 and http://stackoverflow.com/questions/123559/a-comprehensive-regex-for-phone-number-validation?rq=1 –  Sep 25 '16 at 07:45
  • these link is not solving my query i want mixture regex for single input in which single regex can find out both valid email or valid mobile – Amy Sep 25 '16 at 07:49

1 Answers1

0

For 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 ");
    }
}

Use this Regular Expression with Node JS

/^([_a-z0-9]+(.[_a-z0-9]+)@[a-z0-9-]+(.[a-z0-9-]+)(.[a-z]{2,5}))|(\d+$)$/

Demo

Milan Malani
  • 1,818
  • 1
  • 22
  • 34
  • please change this regex /^([_a-z0-9]+(.[_a-z0-9]+)@[a-z0-9-]+(.[a-z0-9-]+)(.[a-z]{2,5}))|(\d+$)$/ to 10 digit mobile number which start from 7,8,9 – Amy Sep 25 '16 at 08:59