hi
I need to validate the user name.it should contain alphanumeic characters and an underscore .
how do we validate a statement which we take from a textbox to have alpnumeric values and spaces...
thanks a lot
gaurav
| SitePoint Sponsor |
hi
I need to validate the user name.it should contain alphanumeic characters and an underscore .
how do we validate a statement which we take from a textbox to have alpnumeric values and spaces...
thanks a lot
gaurav
something on the order of:
perhaps?Code:>> def is_good?(name) >> return true if name =~ /[a-zA-Z]+_[a-zA-Z]*/ >> return false >> end => nil >> is_good? "badname" => false >> is_good? "good_name" => true
Jason Sweat ZCE - jsweat_php@yahoo.com
Book: PHP Patterns
Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
Detestable (adjective): software that isn't testable.
Thanks a lot its working good



You might want to look at this, it'd be better:
http://api.rubyonrails.org/classes/A...s.html#M000659
Useing this code in your model:
If you're using a model, that is.Code:validates_format_of :name, :with => /[a-zA-Z]+_[a-zA-Z]*/
Bookmarks