Forum: Ruby on Rails Include? characters javascript validation

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F677fa685a2cfe8aff31f161062db3d3?d=identicon&s=25 David (Guest)
on 2008-12-10 13:25
(Received via mailing list)
I am trying to write my own javascript validation and am looking for
some help with writing a function that checks to see if a string
contains invalid characters.  I have gotten it to work for spaces:

username.include?(' ')

but I would like to perform a thorough check for all invalid
characters like my user validation:

validates_format_of :username,  :with => /^[A-Z0-9_]*$/i

Im a little confused about the /^[A-Z0-9_]*$/i syntax.  Can anyone
enlighten me?
9f9c3cd0120e224edb912be6e706f125?d=identicon&s=25 Iain Adams (Guest)
on 2008-12-10 13:48
(Received via mailing list)
/^[A-Z0-9_]*$/i  is a regular expression.

Basically

^                    denotes starts with
[A-Z0-9_]*     denotes 0 or more capitals, numbers and underscores
$                   denotes ends_with

The i at the end means to ignore case (i think).

Thus your username can only contain letters, numbers and underscores
and nothing else.

The regular expression is contained between the //

If you were wanting to do this in a javascript function you will have
to investigate using regular expressions in javascript.
The syntax should be the same for the actual regular expression.
This topic is locked and can not be replied to.