javascript - Regular expression X characters long, alphanumeric but not _ and periods, but not at beginning or end -
as subject indicates, in need of javascript regular expression x characters long, accepts alphanumeric characters, not underscore character, , accepts periods, not @ beginning or end. periods cannot consecutive either.
i have been able want searching , reading other people's questions , answers here on stack overflow (such here).
however, in case, need string has x characters long (say 6), , can contain letters , numbers (case insensitive) , may include periods.
said periods cannot consecutive , also, cannot start, or end string.
jd.1.4
valid, jdf1.4f
not (7 characters).
/^(?:[a-z\d]+(?:\.(?!$))?)+$/i
is have been able construct using examples others, cannot accept strings match set length.
/^((?:[a-z\d]+(?:\.(?!$))?)+){6}$/i
works in accepts nothing less 6 characters, happily accepts longer well...
i missing something, not know is.
can help?
this should work:
/^(?!.*?\.\.)[a-z\d][a-z\d.]{4}[a-z\d]$/i
explanation:
^ // matches beginning of string (?!.*?\.\.) // negative lookahead, matches if there no // consecutive periods (.) [a-z\d] // matches a-z , digit [a-z\d.]{4} // matches 4 consecutive characters or digits or periods [a-z\d] // matches a-z , digit $ // matches end of string
Comments
Post a Comment