开发者

Preg_match - checking alphanumeric

开发者 https://www.devze.com 2023-03-26 04:43 出处:网络
I feel super fail asking this... but I\'ve been trying to make sure my values are alphanumeric, and I can\'t do it!

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 k开发者_StackOverflow社区now of a resource (aside from PHP.net) that has a list of operators for Preg_match, and what they mean?

Thanks!


The function ctype_alnum() is better in this case.

For the operators : official stuff.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消