regular expression: low-caps and must contain a dot

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lauthiamkok
Forum Contributor
Posts: 153
Joined: Wed Apr 01, 2009 2:23 pm
Location: Plymouth, United Kingdom

regular expression: low-caps and must contain a dot

Post 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
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

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

Post 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)
Post Reply