Thomas said:
pr said:
Thomas said:
pr wrote:
Dr J R Stockton wrote:
how can i compile a user to enter both characters (a-z and A-Z)
and numbers while inputting a password field, with its length in
between 8 and 14 using Regular expression and the sting may also
contain either _ or - with it
An obvious solution is:
OK = /^[\da-z_-]{8,14}$/i.test(s) && /\d.*[a-z]|[a-z].*\d/i.test(s)
[...]
Dr Stockton's version is right, AFAICS.
ACK, and not using .* there is even more efficient.
You can't remove .* from Dr Stockton's expression, because the digit may
be separated from the alphabetical character by one or more (or no) '_'
or '-'.
[...]
Finally, I was about to say "Good catch about \w, though." Yet AIUI,
section 2 of the Specification indicates that /\w/ as a substitute for ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/[0-9A-Z_]/i cannot be trusted.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I have a vague memory of a browser once upon a time in a non-English
locale interpreting \w to include some local characters, but that is
likely to have been in the distant past. Section 15.10.2.12 of ECMA-262
is refreshingly exact about the characters that 'CharacterClassEscape ::
w' is intended to represent these days.
But did you consider section *2* as well?
| A conforming implementation of ECMAScript is permitted to support program
| and regular expression syntax not described in this specification. [...]
AIUI, this also means a conforming implementation may implement \w
differently than described in the Specification.
The way I read it, the first paragraph is the most important:
| A conforming implementation of ECMAScript must provide and support
| all the types, values, objects, properties, functions, and program
| syntax and semantics described in this specification.
So it must provide regular expressions and the '\w' escape as described.
| A conforming implementation of ECMAScript is permitted to provide
| additional types, values, objects, properties, and functions beyond
| those described in this specification.
and
| A conforming implementation of ECMAScript is permitted to support
| program and regular expression syntax not described in this
| specification.
I take to mean that the implementation may supply *additional* objects,
properties, syntax, etc. over and above what is described. So '\w' must
conform to its description, but there is no reason why an implementation
can't introduce a '\q' sequence that matches quote marks (say), or
lookbehinds, or some wholly new and imaginative property of the RegExp
object.
That would just be my opinion, however.