how do I write an expression which checks for lowcaps, dots, and without any white space in the string?
the code below so far was trying to check for lowcaps and dots (i
[a-z0-9.] matches a lower-case letter or a digit or a dot.
[^a-z0-9.] matches all characters that are not a lower-case letter or a digit or a dot.
So if /[^a-z0-9.]/ matches anywhere the string contains something other than lc-letter,digit or dot. If it does not match your condition is fulfilled.
if ( !preg_match('/[^a-z0-9.]/', $cst_value) ) {
// only lower-case letters, digits or dots
}
or without digits
if ( !preg_match('/[^a-z.]/', $cst_value) ) {
// only lower-case letters or dots
}
update: example:
foreach( array('abcdef', 'abc de', 'abc.de', 'aBcde') as $cst_value) {
echo $cst_value, ': ';
if ( !preg_match('/[^a-z.]/', $cst_value) ) {
echo " ok.\n";
}
else {
echo "failure\n";
}
}
prints
abcdef: ok.
abc de: failure
abc.de: ok.
aBcde: failure