Hi there,
i'm trying to make a regex, but it ain't working.
In just one regex expression I want to check a password that must meet
following requirements:
- at least 6 characters long
- at least one letter (doesn't matter where in te string)
- at least one number (doesn't matter where in te string)
(those are no prob)
- excluding 0, o, O, i, I, l, L, 1 (to prevent confusion about
password chars when font is for ex. Arial)
Can anyone help?
Thanks
Christ. 9 3041
Christ wrote: i'm trying to make a regex, but it ain't working.
"It doesn't work" is a useless error *description*.
What have you already tried? What errors have occured
on which line?
PointedEars
"Christ" <ch**************@hotmail.com> skrev i melding
news:36**************************@posting.google.c om... Hi there,
i'm trying to make a regex, but it ain't working. In just one regex expression I want to check a password that must meet following requirements: - at least 6 characters long - at least one letter (doesn't matter where in te string) - at least one number (doesn't matter where in te string) (those are no prob) - excluding 0, o, O, i, I, l, L, 1 (to prevent confusion about password chars when font is for ex. Arial)
Can anyone help?
Thanks
Christ.
Why use regex? Isn't there much more easier to just traverse the string to
see if you can find a number, a letter and an "if password.length > 5 { " to
check the length ? I would do it that way. ch**************@hotmail.com (Christ) writes: In just one regex expression I want to check a password that must meet following requirements:
Why just one regular expression? Sure, anything you can make with more
than one regular expression can be made with just one, but the size of
the one can easily be the product of the sizes of the many (and
shorthands make it worse, since they typically apply to simple
expressions more than complex ones)
- at least 6 characters long
input.length >= 6
- at least one letter (doesn't matter where in te string)
(/[a-hj-kmnp-z]/i).test(input)
- at least one number (doesn't matter where in te string)
(/[2-9]/).test(input)
(those are no prob) - excluding 0, o, O, i, I, l, L, 1 (to prevent confusion about password chars when font is for ex. Arial)
Combining these in one expression will give you a *huge* expression,
I can tell you that without trying.
There is one shorthand that can help you, though: look-ahead. It
only exist in recent versions of Javascript, though.
/^(?=.*[2-9])(?=.*[a-hj-kmnp-z]).{6,}/i
^^^^^^^^^^^ look-ahead contains at least one of 2-9
^^^^^^^^^^^^^^^^^^^ look-ahead contains a letter, not i,l,o
^^^^^ at least six characters
It seems to me that IE has a problem with positive lookahead:
/^(?=.+4)123/.test("1234")
This test should give true. In IE it gives false. However,
/^(?=.+4)123/.test("12345")
does give true. Changing + to * just makes it worse.
Some times, using just one regular expression is shooting your own foot.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Lasse Reichstein Nielsen <lr*@hotpop.com> writes: /^(?=.*[2-9])(?=.*[a-hj-kmnp-z]).{6,}/i
Doh. That doesn't prevent the remaining characters from being o, i, l,
1, or 0. For that, do:
/^(?=.*[2-9])(?=.*[a-hj-kmnp-z])[^oil01]{6,}/i
However, that also allows characters like |, !, ó, ò, ô, etc. These might
also be confuzed with each other. If you just want digits and characters,
change [^oil01] to [2-9a-hjkmnp-z].
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
JRS: In article <ad**********@hotpop.com>, seen in
news:comp.lang.javascript, Lasse Reichstein Nielsen <lr*@hotpop.com>
posted at Thu, 16 Oct 2003 13:46:37 :- - at least 6 characters long
input.length >= 6
- at least one letter (doesn't matter where in te string)
(/[a-hj-kmnp-z]/i).test(input)
- at least one number (doesn't matter where in te string)
(/[2-9]/).test(input)
I'd do
(/^[a-hj-kmnp-z2-9]{6,}$/i).test(input)
instead of the first; it also checks that all characters are reasonable
- " A 3 " is in accordance with the stated - presumed homework -
requirement but is not a good password.
The later tests can use [a-z] and \d then.
However, passwords should not appear on the screen when typing, so
screen font does not matter; and if they have to be communicated in
writing that can be done in a sensible font.
Since L can, he says, be confused, presumably case does not matter; in
that case, the restriction to 31 of 36 alphanumerics reduces security by
about 60%.
The minus between j & k seems unnecessary.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Lasse Reichstein Nielsen <lr*@hotpop.com> wrote in message news:<65**********@hotpop.com>... Lasse Reichstein Nielsen <lr*@hotpop.com> writes:
/^(?=.*[2-9])(?=.*[a-hj-kmnp-z]).{6,}/i
Doh. That doesn't prevent the remaining characters from being o, i, l, 1, or 0. For that, do: /^(?=.*[2-9])(?=.*[a-hj-kmnp-z])[^oil01]{6,}/i
However, that also allows characters like |, !, ó, ò, ô, etc. These might also be confuzed with each other. If you just want digits and characters, change [^oil01] to [2-9a-hjkmnp-z].
/L
Seems you intended to add a $ anchor to really ensure no extraneous
characters at the end of the string:
/^(?=.*[2-9])(?=.*[a-hj-kmnp-z])[2-9a-hj-kmnp-z]{6,}$/i
However, while Opera 7.11 appears to handle this correctly, Netscape
7.1 (as well as IE) has problems with lookahead. So for something that
should be equivalent and stand a chance of working generally:
/[a-z]\d|\d[a-z]/i.test(pwStr)
&& /^[2-9a-hj-kmnp-z]{6,}$/i.test(pwStr)
Dr John Stockton <sp**@merlyn.demon.co.uk> wrote in message news:<5S**************@merlyn.demon.co.uk>... JRS: In article <ad**********@hotpop.com>, seen in news:comp.lang.javascript, Lasse Reichstein Nielsen <lr*@hotpop.com> posted at Thu, 16 Oct 2003 13:46:37 :-
The minus between j & k seems unnecessary.
Right, it is. Probably a typo in placing the dash -- [a-h-jkmnp-z] was
the sequence intended, I believe, to eliminate i/I as per the OP. co********@yahoo.ca (rh) wrote in message news:<29**************************@posting.google. com>... Dr John Stockton <sp**@merlyn.demon.co.uk> wrote in message news:<5S**************@merlyn.demon.co.uk>... JRS: In article <ad**********@hotpop.com>, seen in news:comp.lang.javascript, Lasse Reichstein Nielsen <lr*@hotpop.com> posted at Thu, 16 Oct 2003 13:46:37 :-
The minus between j & k seems unnecessary.
Right, it is. Probably a typo in placing the dash -- [a-h-jkmnp-z] was the sequence intended, I believe, to eliminate i/I as per the OP.
And then again on this one perhaps it would have been better to say
"Right it is.", or better yet nothing at all :-).
Lasse Reichstein Nielsen <lr*@hotpop.com> wrote in message news:<ad**********@hotpop.com>... ch**************@hotmail.com (Christ) writes:
In just one regex expression I want to check a password that must meet following requirements:
/^(?=.*[2-9])(?=.*[a-hj-kmnp-z]).{6,}/i ^^^^^^^^^^^ look-ahead contains at least one of 2-9 ^^^^^^^^^^^^^^^^^^^ look-ahead contains a letter, not i,l,o ^^^^^ at least six characters
It seems to me that IE has a problem with positive lookahead: /^(?=.+4)123/.test("1234") This test should give true. In IE it gives false. However, /^(?=.+4)123/.test("12345") does give true. Changing + to * just makes it worse.
Lookahead in a RegExp is supposed to be a zero-width assertion. In
addition to the above problems, IE 6 "eats characters" in the
lookahead. Netscape 6.1 and Mozilla 5/1.2b, by some coincidence, do
the same.
Opera 7.11 gets it right (and appears to match Perl behaviour) in a
limited number of tests performed.
So it seems that lookahead in a js RegExp is something that should be
strictly avoided, unless one is authoring for a very specific js
environment that can properly support it.
..\rh This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Tim Conner |
last post by:
Is there a way to write a faster function ?
public static bool IsNumber( char Value )
{
if (Regex.IsMatch( Value.ToString(), @"^+$" ))
{
return true;
}
else return false;
}
|
by: jeevankodali |
last post by:
Hi
I have an .Net application which processes thousands of Xml nodes each
day and for each node I am using around 30-40 Regex matches to see if
they satisfy some conditions are not. These Regex...
|
by: Aaron |
last post by:
I would like to randomly output phone numbers seperated by \ and / from a string.
s = "\231-3423/\453-1234/\231-3473/\231-3474/"
//c sharp code
private string GetPhoneNum()
{
s =...
|
by: skavan |
last post by:
Hi,
I'm just wrapping my head around regex and am pretty sure it can do the
task at hand - but it's too complex for my brain to process -- so am
throwing it out there for you experts to comment...
|
by: skavan |
last post by:
Use Case:
We have music files that describe, in their filename, attributes of the
music.
We do not know a general pattern that applies to all filenames -- but
we do know that filenames that are...
|
by: Extremest |
last post by:
I have a huge regex setup going on. If I don't do each one by itself
instead of all in one it won't work for. Also would like to know if
there is a faster way tried to use string.replace with all...
|
by: Extremest |
last post by:
I am using this regex.
static Regex paranthesis = new Regex("(\\d*/\\d*)",
RegexOptions.IgnoreCase);
it should find everything between parenthesis that have some numbers
onyl then a forward...
|
by: aspineux |
last post by:
My goal is to write a parser for these imaginary string from the SMTP
protocol, regarding RFC 821 and 1869.
I'm a little flexible with the BNF from these RFC :-)
Any comment ?
tests=
def...
|
by: morleyc |
last post by:
Hi, i would like to remove a number of characters from my string (\t
\r \n which are throughout the string), i know regex can do this but i
have no idea how. Any pointers much appreciated.
Chris
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |