user866339
user866339

Reputation: 439

Preg_match - checking alphanumeric

I feel super fail asking this... but I've been trying to make sure my values are alphanumeric, and I can't do it! if(!preg_match("^[0-9]+:[a-zA-Z]+$/", $subuser)){ $form->setError($field, "* Username not alphanumeric"); }

I did a search here and couldn't find anything... probably because this is so rudimentary =__=

Also, does anyone know of a resource (aside from PHP.net) that has a list of operators for Preg_match, and what they mean?

Thanks!

Upvotes: 0

Views: 4065

Answers (2)

Devin Ceartas
Devin Ceartas

Reputation: 4829

if you just want to make sure they are alphanumeric,

if( preg_match(/\W/), $subuser) {  
  $form->setError($field, "* Username not alphanumeric"); 
}

will work (match any non-alphanumeric entry). But it looks like your username might require some structure.

I thought "Mastering Regular Expressions" was one of the better programming books I've read, and I've read at least a couple hundred by now.

http://www.amazon.com/Mastering-Regular-Expressions-Jeffrey-Friedl/dp/0596528124/ref=sr_1_1?ie=UTF8&qid=1312676428&sr=8-1

Upvotes: 0

Ayell
Ayell

Reputation: 620

The function ctype_alnum() is better in this case.

For the operators : official stuff.

Upvotes: 3

Related Questions