plutomed Posted February 16, 2007 Share Posted February 16, 2007 my friend tryed to help me with but i still dont get it ??? i have a form with an email field how do make sure the user put an @ and a . in the field? Quote Link to comment Share on other sites More sharing options...
effigy Posted February 16, 2007 Share Posted February 16, 2007 What code have you tried? Quote Link to comment Share on other sites More sharing options...
plutomed Posted February 16, 2007 Author Share Posted February 16, 2007 <script language="javascript" type="text/javascript"> var myRegxp = /^[\d\w]@[\d\w]\.[\d\w]$/g; document.write(myRegxp.test(<? $_POST['email'] ?>)); </script> thats proberly wrong because i tryed to change it and i copied it of another site Quote Link to comment Share on other sites More sharing options...
effigy Posted February 16, 2007 Share Posted February 16, 2007 If you're reading $_POST directly, why not use PHP? <script language="javascript" type="text/javascript"> var regex_valid_email = /^[-\w.]+@[-\w.]+\.[A-Za-z]{2,4}$/; function verify_email (obj) { if (regex_valid_email.test(obj.value)) { alert('Valid'); } else { alert('Invalid'); } } </script> <input type="text" name="email" onblur="verify_email(this);"/> Quote Link to comment Share on other sites More sharing options...
plutomed Posted February 16, 2007 Author Share Posted February 16, 2007 ok thankyou how do you do it with php then if its easier Quote Link to comment Share on other sites More sharing options...
effigy Posted February 16, 2007 Share Posted February 16, 2007 Use PHP's preg_match function. Quote Link to comment Share on other sites More sharing options...
plutomed Posted February 16, 2007 Author Share Posted February 16, 2007 ok thankyou Quote Link to comment Share on other sites More sharing options...
plutomed Posted February 16, 2007 Author Share Posted February 16, 2007 can u post a link to all the php regex or write them please Quote Link to comment Share on other sites More sharing options...
effigy Posted February 16, 2007 Share Posted February 16, 2007 Here's an example. There are regex links in my signature. <?php if ($_POST) { echo preg_match('/^[-\w.]+@[-\w.]+\.[A-Za-z]{2,4}\z/', $_POST['email']) ? 'OK' : 'Not OK' ; echo '<br><a href="', $_SERVER['PHP_SELF'], '">Test again</a>'; } else { ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input type="text" name="email"> <input type="submit"> </form> <?php } ?> Quote Link to comment Share on other sites More sharing options...
plutomed Posted February 16, 2007 Author Share Posted February 16, 2007 thanks for your help i got it workin now ;D Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.