Page 1 of 1

regular expression: low-caps and must contain a dot

Posted: Thu Aug 26, 2010 5:10 pm
by lauthiamkok
hi,

how do I write an expression which checks for low-caps and must contains a dot.

the code below will accept the input with or without a dot... but I want it accept the input only with a least a dot...

Code: Select all

$values=array("fooBar", "12345", "foo bar", "foo.bar", "http://lauthiamkok.net");

foreach($values as $value) {
    if (!preg_match('/^[a-z0-9.:\/\/]+$/', $value))
    {
         echo "Not valid: $value <br>";
    }
}

//RESULT
//Not valid: fooBar
//Not valid: foo bar 


any ideas?

many thanks,
Lau

Re: regular expression: low-caps and must contain a dot

Posted: Thu Aug 26, 2010 6:59 pm
by Jonah Bron
Escape the dot: it is a wildcard that represents any character but a new line.

Code: Select all

preg_match('/^[a-z0-9.:\/\/]+$/', $value)
Becomes

Code: Select all

preg_match('/^[a-z0-9\.:\/\/]+$/', $value)