# Include? characters javascript validation

**URL:** <https://www.ruby-forum.com/t/include-characters-javascript-validation/155310>\
**Category:** Rails\
**Created:** [December 10, 2008, 1:25pm UTC](https://www.ruby-forum.com/t/include-characters-javascript-validation/155310 "2008-12-10T13:25:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [December 10, 2008, 1:25pm UTC](https://www.ruby-forum.com/t/include-characters-javascript-validation/155310/1 "2008-12-10T13:25:05Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [December 10, 2008, 1:48pm UTC](https://www.ruby-forum.com/t/include-characters-javascript-validation/155310/2 "2008-12-10T13:48:36Z")

</div>

/^[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.
