Jump to content

[SOLVED] Allowing alphabetic and numbers only


9three

Recommended Posts

When I use the pattern you provided it gives me an error

 

if (!preg_match('^[a-zA-Z0-9]+$', $strUsername))

 

^[a-zA-Z0-9]+$
Warning: preg_match() [function.preg-match]: No ending delimiter '^' found

 

I tried somethings like adding a / at the end but it was no good.

 

:(

This is because in preg, you need to encase the entire pattern in delimiters... so in your case, you can use:

 

if (!preg_match('#^[a-z0-9]+$#i', $strUsername)) // note the opening and closing #.. I also used the i modifier for case insensitivity

 

Delimiters can be any non alphanumeric, non whitespace ASCII character (except a backslash). You can read up about delimiters here:

 

http://www.phpfreaks.com/forums/index.php/topic,95777.0.html

As well as the pcre portion of the manual.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.