SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Replace eregi?

  1. #1
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    645
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Replace eregi?

    I have an old script that I am reusing in a new one.
    But I think I read somewhere that eregi is something one should not use anymore.
    What should I replace my line with then?

    I have a form where people register. My script is supposed to check that the fields are correct.
    That they actually write their name, e-mail and so on.

    The one I have now is:
    PHP Code:
    if($user_name != "" && eregi('[a-z | A-Z]+',$user_name)){
    $debug=TRUE;
    } else {
    $debug=FALSE;
    $message[]="<span class='error'>You need to fill in a correct name</span><br />";

    That one is looking for letters in the field.
    What should I replace this code with in my script?

    And... this time I want the code to work in other languages too. I need people to be able to use swedish charcters ( , ) and german (like or or whatever). I guess my code is only accepting a-z and A-Z.

    Is there a way to make my code work in a better way?

  2. #2
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might check http://www.freecontactform.com/email_form.php
    They have there something like:

    $string_exp = "/^[A-Za-z .'-]+$/";
    if(!preg_match($string_exp,$first_name)) {
    $error_message .= 'The First Name you entered does not appear to be valid.<br />'; }

    You will be able to build your '$string_exp' as you need...
    Last edited by esn003; Dec 19, 2012 at 05:04. Reason: tipo

  3. #3
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    645
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    But what about other characters (outside of a-z)?

  4. #4
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would try to insert them in '$string_exp' definition but outside the '[ ]' or go comparing their hex value (like we used to do with ASCII) if you are in UTF8

  5. #5
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What about the 'preg_match'? Did it work?


Bookmarks

Posting Permissions

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