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? Link to comment https://forums.phpfreaks.com/topic/38795-solved-regular-expressions/ Share on other sites More sharing options...
effigy Posted February 16, 2007 Share Posted February 16, 2007 What code have you tried? Link to comment https://forums.phpfreaks.com/topic/38795-solved-regular-expressions/#findComment-186466 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 Link to comment https://forums.phpfreaks.com/topic/38795-solved-regular-expressions/#findComment-186467 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);"/> Link to comment https://forums.phpfreaks.com/topic/38795-solved-regular-expressions/#findComment-186474 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 Link to comment https://forums.phpfreaks.com/topic/38795-solved-regular-expressions/#findComment-186475 Share on other sites More sharing options...
effigy Posted February 16, 2007 Share Posted February 16, 2007 Use PHP's preg_match function. Link to comment https://forums.phpfreaks.com/topic/38795-solved-regular-expressions/#findComment-186477 Share on other sites More sharing options...
plutomed Posted February 16, 2007 Author Share Posted February 16, 2007 ok thankyou Link to comment https://forums.phpfreaks.com/topic/38795-solved-regular-expressions/#findComment-186492 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 Link to comment https://forums.phpfreaks.com/topic/38795-solved-regular-expressions/#findComment-186505 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 } ?> Link to comment https://forums.phpfreaks.com/topic/38795-solved-regular-expressions/#findComment-186516 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 Link to comment https://forums.phpfreaks.com/topic/38795-solved-regular-expressions/#findComment-186530 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.