Reputation: 4173
Can someone help me write the regular expression for validates_format_of.
It should fail if any one of
< > $ \ any_non_printable_characteris present.
Thanks.
Upvotes: 0
Views: 125
Reputation: 434635
Something like this would work with Ruby 1.9:
/\A[^<>\\$\p{^Print}]*\z/
That will match anything that doesn't contain your bad characters and hence should work nicely in a validation. That will also match an empty string though so you could use +
instead of *
or add a length or present?
check if you wanted to exclude ''
.
Upvotes: 2
Reputation: 624
Don't know Ruby, but for Perl, ... the following would work:
if(/(:?[<>\$]|[^[:print:]])/){...}
And in Python, awk, sed, ... it would look more or less the same. So hopefully this helps with Ruby.
Upvotes: 0