473,387 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

More questions about search function on regular expressions

I posed this problem last month here, but need more of a
clarification, as I still cannot correctly flag a bad password. I need
users to submit a passowrd that has at least one numeric character,
along with any amount of string-alpha characters (8 numeric characters
and 1 string character is fine, for example), but having trouble with
the correct regex, as the below still doesnt raise the error alert
when all strings with no numbers are entered:

<script language="JavaScript" type="text/javascript">
function validatePassword(password) {
var error = "";
var illegalChars = /[\W_]/; // allow only letters and numbers

if (password.value == "") {
password.style.background = 'Yellow';
error = "You didn't enter a password.\n";
} else if ((password.value.length < 7) || (password.value.length >
15)) {
error = "The password is the wrong length. \n";
password.style.background = 'Yellow';
} else if (illegalChars.test(password.value)) {
error = "The password contains illegal characters.\n";
password.style.background = 'Yellow';
} else if (!((password.value.search(/[A-Z]+[a-z]+[0-9]/)))){ // &&
(password.value.search(/(0-9)+/)))) {
error = "The password must contain at least one numeral.\n";
password.style.background = 'Yellow';
} else {
password.style.background = 'White';
}
return error;
}

</script>

Thanks in advance
netsports

May 8 '07 #1
2 1598
..Net Sports wrote on 08 mei 2007 in comp.lang.javascript:
I posed this problem last month here, but need more of a
clarification, as I still cannot correctly flag a bad password. I need
users to submit a passowrd that has at least one numeric character,
along with any amount of string-alpha characters (8 numeric characters
and 1 string character is fine, for example), but having trouble with
the correct regex, as the below still doesnt raise the error alert
when all strings with no numbers are entered:

<script type="text/javascript">
do not use: language="JavaScript"
function validatePassword(password) {
make sure password is the right object by using the "this" keyword
password.style.background = 'Yellow';
yellow , no uppercase

if (!((password.value.search(/[A-Z]+[a-z]+[0-9]/)))){ // &&
(password.value.search(/(0-9)+/)))) {
I don't understand these last two lines with // and two { {
password.style.background = 'White';
white

================

Try this, much simpler code:

<script type="text/javascript">

function validatePassword(password) {
password.style.backgroundColor = 'yellow';
if (password.value == '')
return 'You didn't enter a password.\n';
if ((password.value.length < 7) ||
(password.value.length >15))
return 'The password is of the wrong length.\n';
if (/[\W_]/.test(password.value))
return 'The password contains illegal characters.\n';
if (/\d/.test(password.value))
return 'The password must contain at least one numeral.\n';
password.style.backgroundColor = 'white';
return "";
}

</script>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
May 8 '07 #2
Evertjan. wrote on 09 mei 2007 in comp.lang.javascript:
Try this, much simpler code:

<script type="text/javascript">

function validatePassword(password) {
password.style.backgroundColor = 'yellow';
if (password.value == '')
return 'You didn't enter a password.\n';
if ((password.value.length < 7) ||
(password.value.length >15))
return 'The password is of the wrong length.\n';
if (/[\W_]/.test(password.value))
return 'The password contains illegal characters.\n';
if (/\d/.test(password.value))
if (!/\d/.test(password.value))
return 'The password must contain at least one numeral.\n';
password.style.backgroundColor = 'white';
return "";
}

</script>


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
May 8 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Anand Pillai | last post by:
To search a word in a group of words, say a paragraph or a web page, would a string search or a regexp search be faster? The string search would of course be, if str.find(substr) != -1:...
3
by: colinhumber | last post by:
How can I use regular expressions to search for a substring within another substring? For example, if I have the string: "This is * some text <button id="123">Some * text</button>" and I only...
4
by: Amith Singh | last post by:
Hello All, I am using .Net Framework 1.1. Using Regular Expressions I would like to split a word(inserting a blank space) in a string if the word is more than N(say 50) characters. I can do the...
2
by: Mike Hildner | last post by:
I'm receiving bytes over a socket and displaying in a text box. In the responses I receive, some lines are delimited with x0A and others with x0D0A. I'd like to search for x0A and replace with...
4
by: lucky | last post by:
hi there!! i'm looking for a code snipett wich help me to search some words into a particular string and replace with a perticular word. i got a huge data string in which searching traditional...
8
by: Just Me | last post by:
I want to use regular expressions to search a string, give the user the option of replacing, and then maybe replacing the data - using reg expressions for the search and the replace strings. ...
7
by: pyluke | last post by:
I'm parsing LaTeX document and want to find lines with equations blocked by "\", but not other instances of "\" so, in short, I was to match "\" to add to this, I also don't want lines that...
2
by: Shawn B. | last post by:
Greetings, Lets say I have the following expression: (<A|ABBR|ADDRESS|APPLET(\s){1,}(.*?)>(.*?)</A|ABBR|ADDRESS|APPLET) Such that it'll match any HTML tag that opens with the above specified...
47
by: Henning_Thornblad | last post by:
What can be the cause of the large difference between re.search and grep? This script takes about 5 min to run on my computer: #!/usr/bin/env python import re row="" for a in range(156000):...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
0
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...
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.