html5 - Html 5 regex that allow space between characters -
i need regexp fails in every character outside [a-za-z0-9_& -]
space between characters allowed, not empty spaces.
allowed input examples:
group1, group 1, group1, group1 & group2, group1_group2, group1_group2
my html input type :
<input type="text" required name="name" pattern="[a-za-z0-9_& -]+" placeholder="group name" />
the problem single empty space, if put single empty space, pass. if remove space in regex pattern , become: "[a-za-z0-9_&-]+", user won't able input space between string, group 1, how should form pattern?
try regex:
^(?!^ +$)([\w -&]+)$ explanation:
^- start of string(?!^ +$)- negative lookahead validating string should not contain 1 or more spaces between start , end of string([\w -&]+)- capturing 1 or more characters in range[a-za-z0-9_ &-]$- end of string
Comments
Post a Comment