On Sep 1, 2010, at 4:55 PM, Ken Kixmoeller f/h wrote:
> It seems only to be evaluating the first character, in spite of the "+?"
> in there.
The '+' only means it will match one or more of what preceeds it.
> I tried adding numbers in {} but that brought "unexpected"
> results: no rules were enforced at all.
The braces indicate a range of times a match is found: either a single
value (e.g.: x{3} will match 3 x characters in a row), or a range (e.g., x{2,4}
will match 2, 3 or 4 in a row).
> Anyone willing to help me understand what I am doing wrong???
First off, the string.search() function returns the position where the
expression was found. So if the string is all alpha, and you run
value.search(/[a-zA-Z]/), it will return 0, since it found it at the "zero-th"
position (JS is zero-based). If it is not found, search() will return -1. So
since your search reads:
if (document.form_general.passwordverify.value.search(/[a-zA-Z]+/)) {
Zero is considered binary false, so if the first character matches, the
search returns what JS thinks is false, even though it matched. What you need
to do is change the expressions to check for a non-match; i.e., -1:
if (document.form_general.passwordverify.value.search(/[a-zA-Z]+/) === -1) {
...do your code for no alpha characters
}
-- Ed Leafe
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message:
http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the
author, and do not constitute legal or medical advice. This statement is added
to the messages for those lawyers who are too stupid to see the obvious.