2

I have used this pregmatch statement for validating email address

preg_match("^[a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,4})$^", $partner_email)

If i use capital letters it will show an error.How i can change the pregmatch condition for supporting capital letters in email addres Thanks in advance

Warrior
  • 5,168
  • 12
  • 60
  • 87
  • Your regex is wrong. http://stackoverflow.com/questions/1903356/email-validation-regular-expression/1903368#1903368 – SLaks Jul 19 '11 at 14:32
  • You should have a look at [this thread][1]. [1]: http://stackoverflow.com/questions/201323/what-is-the-best-regular-expression-for-validating-email-addresses – ianbarker Jul 19 '11 at 14:33

4 Answers4

2

several ways:

1) change [a-z0-9_+-] to [a-zA-Z0-9_+] in all places

2) use preg_match("/^...$/i", $partner_emal) ... the /i flag makes it case-insensitive

3) use strtolower($partner_email) as the match string.

mkeasling
  • 36
  • 2
1

you can achieve it by adding i flag after the delimiter or as fourth parameter to preg_match()

Teneff
  • 30,564
  • 13
  • 72
  • 103
  • The fourth parameter of preg_match doesn't take that kind of flag. Those flags are specific to how it returns the matched data when dealing with string captures. – Zimzat Jul 19 '11 at 15:04
0

One simple way is to just insist that the string is lower-case. This is probably preferable to mucking with (and perhaps debugging) a regex that you did not write and is known to work.

preg_match("^[a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,4})$^", strtolower($partner_email))
Dan Rosenstark
  • 68,471
  • 58
  • 283
  • 421
-1

Swap a-z for a-Z

10morechars....

Doug McK
  • 468
  • 5
  • 15
  • 2
    That's backwards, as it should be A-z. But beyond that, that also includes the characters [ \ ] ^ _ `, which are between the A-Z and a-z in the character range. – Zimzat Jul 19 '11 at 14:39