-6

I have a RegExp for e-mail check on the user side in JavaScript like this:

var uzorak = new RegExp("^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$");

and i would like to rename it to PHP RegExp for the server side check.

  • There isn't that much difference between the two, so have you tried just copying it into the appropriate PHP function? That said, that regex will fail a lot of valid addresses, so you're better off using either a much simpler check, or a much more complex one. PHP's filter functions have one built in, for instance http://php.net/filter – IMSoP May 31 '18 at 09:29

1 Answers1

-1

$("#Save").click(function(){
var uzorak = new RegExp("^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$");

var EmailAddress = $("#txt1").val();
var uzorak = new RegExp("^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$");

if(!uzorak.test(EmailAddress))
{
  alert('not a valid e-mail address');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<input type="text" Id="txt1"/>
<button id="Save">Save</button>