oo00oo
January 20, 2006, 8:30pm
1
Hello,
I try this :
validates_format_of :name , :with => /^[A-z0-9_.- ]*$/ , :message =>
“bad characters”
for accept any name with chars “A” to “z” , “0” to “9” , with “_” “.”
“-” and " "
The pattern is really simple but I have this error :
SyntaxError in Login#register
./script/…/config/…/app/models/user.rb:6: invalid regular expression:
/^[A-z0-9_.- ]*$/
This is strange. I forgot something ?
oo00oo
January 20, 2006, 10:49pm
2
On Jan 20, 2006, at 10:52 AM, oo00oo wrote:
The pattern is really simple but I have this error :
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails
Try this regex instead:
/^[a-zA-Z0-9_.-]*$/
Cheers-
-Ezra Z.
WebMaster
Yakima Herald-Republic Newspaper
[email protected]
509-577-7732
oo00oo
January 20, 2006, 11:29pm
3
At 1/20/2006 01:52 PM, you wrote:
The pattern is really simple but I have this error :
SyntaxError in Login#register
./script/…/config/…/app/models/user.rb:6: invalid regular
expression: /^[A-z0-9_.- ]*$/
This is strange. I forgot something ?
You can’t have [.- ] because that looks like the range from ‘.’ to ’
’ and space is lower than full-stop.
Try: /^[A-z0-9 _.-]$/ or (as someone suggested: /^[A-Za-z0-9
_.-] $/ if you didn’t intend [ (0x5B), \ (0x5C), ] (0x5D), ^ (0x5E),
_ (0x5F), and ` (0x60) to be included between Z and a)
-Rob
oo00oo
January 21, 2006, 3:29am
4
In other words, if you want your regular expression to match a hypen, it
must be the first or the last character within the []:
/^[A-z0-9_. -]$/
/^[-A-z0-9_. ] $/
Also, are you sure you want the * quantifier, as this will also match
the empty string. Using + may be what you are looking for in this case.
/^[-A-z0-9_. ]+$/
Cheers,
Bob
Rob B. wrote:
At 1/20/2006 01:52 PM, you wrote:
The pattern is really simple but I have this error :
SyntaxError in Login#register
./script/…/config/…/app/models/user.rb:6: invalid regular
expression: /^[A-z0-9_.- ]*$/
This is strange. I forgot something ?
You can’t have [.- ] because that looks like the range from ‘.’ to ’
’ and space is lower than full-stop.
Try: /^[A-z0-9 _.-]$/ or (as someone suggested: /^[A-Za-z0-9
_.-] $/ if you didn’t intend [ (0x5B), \ (0x5C), ] (0x5D), ^ (0x5E),
_ (0x5F), and ` (0x60) to be included between Z and a)
-Rob
oo00oo
January 21, 2006, 11:33am
5
Oh yes from “.” to " ", I understand my mistake.
I also use + instead *
Thanks to all !