0

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?

KingCrunch
  • 128,817
  • 21
  • 151
  • 173
blömpæ
  • 375
  • 2
  • 12

2 Answers2

2

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.

  • **you** are welcome. so now tick check the green answer tick next to the question. –  Aug 02 '12 at 20:10
0
if (preg_match('~\.~', $notes)) {
  // Do something useful
}
KingCrunch
  • 128,817
  • 21
  • 151
  • 173
  • "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. " –  Aug 02 '12 at 19:51
  • @Dragon Yeah, sure, late here ;) Currently I'm waiting, that you'll post that as answer (because I face-palmed myself when reading your comment above). – KingCrunch Aug 02 '12 at 19:52