I have one form field. In that field it's possible for user to enter EMAIL or MOBILE. From a PHP page i got value. After that i want to check whether this is email id or mobile number. suppose email
means i want to email success,suppose mobile
means i want to show mobile success ,i think we have to write regular expression,but i don't know how to write regular expression for this problem?
<form action="#" method="POST" id="forgotForm">
<div class="form-group has-feedback">
<input type="text" class="form-control" placeholder="Email OR Mobile" id="email" name="email" value="" aria-required="true" required="" data-msg-required="Please enter your email">
<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
</div>
</form>
home.php
<?php
$email=$_POST['email'];//here value it will come like 9986128658 or admin@gmail.com
?>
You can check the input using
preg_match
Checks for the valid email
aa@aa.aa
/^\w{2,}@[\w\.]{2,}\.\w{2,4}$/
Checks for the valid mobile
$mobilePattern
to/^[0-9]{10}$/
You can check if the value is a valid email address. If it is then you have an email, otherwise you can assume that it is a phone number: