Validate access to object field

Ok, now I manage to access field with self.name

But there is still the regular expression to create :

I need name composed of a to z A to Z dash - underscore _

I tried different combination without success

How can I test this

David Nguyen wrote:

Ok, now I manage to access field with self.name

But there is still the regular expression to create :

I need name composed of a to z A to Z dash - underscore _

match /[a..z A..Z - _]*/ or /[a..z - _]*/i

David Nguyen wrote:

Ok, now I manage to access field with self.name

But there is still the regular expression to create :

I need name composed of a to z A to Z dash - underscore _

match /[a..z A..Z - _]*/ or /[a..z - _]*/i --

That doesn't work, for two reasons: 1) - is a special character in a character class, so it has to be the
first character in the character class (ie [-...]) 2) That aside, that regular expression will match any string, because
all it says is 'the string contains 0 or more of those characters'. You need to anchor it: \A matches the beginning of a string \z matches
the end: so /\AHi\z/ will match the string Hi but not the string Hiatus, whereas / Hi/ will match both (there are other anchors with slightly different
semantics: ^ and $ match the beginning and end of lines, and \Z
matches the end of the string, excluding any trailing \n

Fred