#1
  1. No Profile Picture
    Banned
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Apr 2005
    Posts
    4,982
    Rep Power
    0

    Validating String


    I have an odd input string I need to validate. Something like this:

    integer ... integer|integer|integer

    A string of integers. If more than one, seperated by "|"

    A regex maybe? Other ideas?
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    29
    Rep Power
    0
    Originally Posted by Arty Ziff
    I have an odd input string I need to validate. Something like this:

    integer ... integer|integer|integer

    A string of integers. If more than one, seperated by "|"

    A regex maybe? Other ideas?
    RegExp is fine for this, you could write an algorithm but it's complicated.


    Code:
    $string="123|134|555";
    if (preg_match("/^\d+(\|\d+)*$/", $string)) {echo "String correct";}

    Comments on this post

    • Arty Ziff agrees

IMN logo majestic logo threadwatch logo seochat tools logo