# Validate against special characters \*; ' \* ^ } { \[ \] \>\<|

**URL:** <https://www.ruby-forum.com/t/validate-against-special-characters/72868>\
**Category:** Rails\
**Created:** [October 19, 2006, 3:17pm UTC](https://www.ruby-forum.com/t/validate-against-special-characters/72868 "2006-10-19T15:17:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dc4da7/32.png) [@newbie](https://www.ruby-forum.com/u/newbie)\
**Post date:** [October 19, 2006, 3:17pm UTC](https://www.ruby-forum.com/t/validate-against-special-characters/72868/1 "2006-10-19T15:17:29Z")

</div>

i’m sorry for posting such a stupid (and somewhat unconnected) question,  
but i’ve been stuck on this for over a couple good hours (probably due  
to a lack of knowledge in regexp) so if anyone could give a hand, i’d  
most appreciate it…

i’m trying to validate my site against these characters

## thesechars ## \*; ’ \* ^ } { [] \>\< |

and so i’ve decided i’d use validates\_format\_of /^[^thesechars]$/  
but it’s not working! is there a different method i should be using?

many thanks,

newbie

---

<div class="post-metadata">

**Author:** ![newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dc4da7/32.png) [@newbie](https://www.ruby-forum.com/u/newbie)\
**Post date:** [October 19, 2006, 4:55pm UTC](https://www.ruby-forum.com/t/validate-against-special-characters/72868/2 "2006-10-19T16:55:57Z")

</div>

On 10/19/06, newbie [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> i’m sorry for posting such a stupid (and somewhat unconnected) question,  
> but i’ve been stuck on this for over a couple good hours (probably due  
> to a lack of knowledge in regexp) so if anyone could give a hand, i’d  
> most appreciate it…
> 
> i’m trying to validate my site against these characters
> 
> ## thesechars ## \*; ’ \* ^ } { [] \>\< |
> 
> and so i’ve decided i’d use validates\_format\_of /^[^thesechars]$/

My regexp kung-fu is not the strongest, but it looks like you’ve only  
allowed for a single charachter here.

You may need to allow for some more  
validates\_format\_of /^[^thesechars]+$/

You may want to consider this around the other way though. Instead of  
forbidding chars, allow a restricted set.  
validates\_format\_of /^\w+$/ will restrict the values allowable (maybe  
too  
much so). You’ll need to check the docs to tune it to your specific  
need.
