SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jan 2005
    Location
    india
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question validation woe's

    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

  2. #2
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    something on the order of:

    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
    perhaps?
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  3. #3
    SitePoint Member
    Join Date
    Jan 2005
    Location
    india
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot its working good

  4. #4
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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:
    Code:
    validates_format_of :name, :with => /[a-zA-Z]+_[a-zA-Z]*/
    If you're using a model, that is.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •