DOT Validetor Using if (eregi

230 Views Asked by At

Is it possible to use a dot . checker in a email form, so that if specific field have a dot, then this will tell the user to do not put dot in those field. I have tried with this but don't works:

if (eregi('.', $notes)) {
    die ("Do NOT PUT DOT HERE");
}

So, any idea what to do?

2

There are 2 best solutions below

1
On BEST ANSWER

as the manual says:

Tip: Do not use preg_match() if you only want to check if one string is contained in another string. Use strpos() or strstr() instead as they will be faster.

here is the strpos() method:

<?php

$findme   = '.';
$pos = strpos($notes, $findme);

if ($pos !== false) {
     echo "Do NOT PUT DOT HERE";
} else {
     //other
}

?>

I would not recommend die\exit in most case.

2
On
if (preg_match('~\.~', $notes)) {
  // Do something useful
}