Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Apr 2010
    Posts
    417
    Thanks
    4
    Thanked 1 Time in 1 Post

    can someone please help me convert the Javascript to PHP

    Code:
    <script type="text/javascript">
    function checkEmailValid(email) {
    	s = email.indexOf(' ') + 1;
    	e = email.indexOf('@') + 1;
    	f = email.indexOf('.') + 1;
    		if ( email != '' && s == 0 && e && f > e + 1 && f < email.length) {
    			return true;
    		} else {
    			return false;
    		}
    }
    </script>
    this would allow i.e.

    1@1.1
    a@a.a

    or any number of characters before and after the @ and the .


    i have tried the regular expresions but these failed for us with various email address so opted for this which work in the javascript version but we now need to use this in PHP on the server side to validate before it is used.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Filtervar:
    PHP Code:
    function verifyEmail($sEmail)
    {
        return 
    filter_var($sEmailFILTER_VALIDATE_EMAIL);
    }

    if (
    false === verifyEmail('email@host.com'))
    {
        print 
    'invalid email.';

    Much easier than pulling the full regexp for email addresses.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •