Thread: string check

    #1
  1. No Profile Picture
    PHP Programmer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    31
    Rep Power
    15
    Hi all,

    I want to check if a string contains only alphabetical and/or numerical characters. I think the solution is eregi, but i am not an expert on regular expressions...

    Help extremely appreciated!
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    You can find out whether the value is string or a numerical value using two functions.

    is_string() and is_int();

    is_string()->This will find out whether variable is a string.

    is_int()->This will find out whether variable is an integer.


    or

    probably you may use gettype() function to find out variable type.

    $type=gettype($value);

    #this will return the type of the variable.



    ------------------
    SR -
    shiju.dreamcenter.net

    "The fear of the LORD is the beginning of knowledge..."
  4. #3
  5. No Profile Picture
    PHP Programmer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    31
    Rep Power
    15
    Thats not what I meant... I want to make sure that a string contains ONLY a-z and 0-9, so that i can provide email-adress to my users.
    I dont want users to hav signs like
    " ' ! @ $ [ ] { }
    ans so on...
  6. #4
  7. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    ohh sorry,

    you can use the ereg() for doing this.

    if (!ereg('^[-!#$%&'*+./0-9=?A-Z^_`a-z{|}~]+', $value){
    //This will check the email validity

    ------------------
    SR -
    shiju.dreamcenter.net

    "The fear of the LORD is the beginning of knowledge..."
  8. #5
  9. No Profile Picture
    PHP Programmer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    31
    Rep Power
    15
    yeah, I know i can use ereg (or eregi), but how does regular expressions work? That's my question!

Similar Threads

  1. array explode ( string separator, string string [, int limit])
    By beemee_freeserv in forum HTML Programming
    Replies: 4
    Last Post: February 5th, 2004, 11:56 AM
  2. mgetty+sendfax on RH9
    By ayrin in forum Linux Help
    Replies: 0
    Last Post: January 31st, 2004, 03:11 AM
  3. Form validation: how do i check string length and type?
    By adamay in forum HTML Programming
    Replies: 3
    Last Post: January 13th, 2004, 11:21 AM
  4. Replies: 28
    Last Post: January 4th, 2004, 02:28 PM
  5. Do compilers optimize some / into *?
    By Jason Doucette in forum C Programming
    Replies: 46
    Last Post: December 25th, 2003, 09:47 PM

IMN logo majestic logo threadwatch logo seochat tools logo