Posted By

alexandrepayet on 08/16/10


Tagged

php test String regular expressions ereg Chaine rationnelle reguliere


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Fylhan


PHP : expressions regulieres les plus courantes et exemple de test avec ereg()


 / Published in: PHP
 

  1. <?php
  2.  
  3. $EXP_num = "^[0-9]+$";
  4. $EXP_num_fixe = "^0262([0-9]){6}$";
  5. $EXP_num_portable = "^069(2|3)([0-9]){6}$";
  6. $EXP_cp = "^974([0-9]){2}$";
  7. $EXP_mail = "^([a-z0-9._-])+@([a-z0-9.-])+(.)([a-z]){2,4}$";
  8. $EXP_nom = "^[a-zA-ZéçèàêëîïôöûüâäÉÀÈËËÏÎÖÔÛÜÄÂ'-][a-zA-ZéçèàêëîïôöûüâäÉÀÈËËÏÎÖÔÛÜÄÂ' -]{2,50}$";
  9. $EXP_date = "^[0-9]{2}/[0-9]{2}/[0-9]{4}$";
  10. $EXP_url = "^http://";
  11. $EXP_alphanum = "^[a-zA-Z0-9_-]$";
  12.  
  13. if(!ereg($EXP_mail, $mail)){ echo "your mail is invalid"; }
  14.  
  15. ?>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: Fylhan on August 16, 2010

Dans l'email, pourquoi pas : $EXPmail = "^[a-z0-9.-].+@([a-z.-])+(.)([a-z]){2,4}$";

??

Posted By: alexandrepayet on September 21, 2010

@Fylhan dans la première partie, il faut conserver l'underscore --> ^[a-z0-9._-]

Posted By: alexandrepayet on September 21, 2010

@Fylhan Par contre tu as raison, on peut se passer des crochets pour ([.]), ce qui nous donne ^[a-z0-9._-].+@([a-z.-])+(.)([a-z]){2,4}$

You need to login to post a comment.