-3

I have a form that people must fill in. There has to be checks if the person filled in the form correctly. Now I need 2 type of checks but I have no clue how to accomplish this. I looked up regular expressions but I only get errors (deprecated??) and I am stuck on tutorials. What I need should be easy enough.

1) string may only contain letters and dots

2) string may only contain letters, dashes - and '

Who can help me?

45808
  • 376
  • 1
  • 3
  • 16

3 Answers3

1

are you using eregi? because that function is deprecated since php 5.3.0.

look this website: http://takien.com/513/how-to-fix-function-eregi-is-deprecated-in-php-5-3-0.php

Stefan Koenen
  • 2,289
  • 2
  • 20
  • 32
  • Yes in fact I did use eregi! Thanks for your comment. I'm going to check out that website. – 45808 Nov 30 '11 at 10:45
1
// (1)
if ( preg_match('/[^\w\.\']/u', $field1) )
    ... check one failed

// (2)
if ( preg_match('/[^\w]/u', $field2) )
    ... check two failed

// (3)
if ( preg_match('/[^\d]/', $field3) )
    ... check three failed

// (4)
if ( preg_match('/[^\w\d]/u', $field4) )
    ... check four failed

// (5) emails cannot be checked a 100% but ...
if ( !preg_match('/^(?:[0-9a-z\_\-]+\.?)+\@(?:[0-9a-z\-]+\.)+[a-z]{2,4}$/i', $field5) )
    ... check five failed
aefxx
  • 24,835
  • 6
  • 45
  • 55
  • Thank you. Number 1 and 2 aren't workin though. 1) I need a string that only allows letters and dots. 2) I only need to allow letters, dash - and ' . 3) I need one with letters only. Can you help me with these 3? – 45808 Nov 30 '11 at 11:06
0

1) string may only contain letters, dots and ' (NOTE: I use mysql_real_escape_string) how do I solve this?

^[A-Za-z0-9.']+$

2) string may only contain letters

Regular Expression to match only letters

3) string may only contain numbers

Regex to match "{number}"

4) string may only contain letters and numbers

combine 2) and 3)

5) check for valid email address

Using a regular expression to validate an email address

Community
  • 1
  • 1
PiTheNumber
  • 22,828
  • 17
  • 107
  • 180