SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
Thread: Validate Password
-
Nov 3, 2002, 15:04 #1
- Join Date
- Sep 2002
- Location
- Canada
- Posts
- 2,087
- Mentioned
- 1 Post(s)
- Tagged
- 1 Thread(s)
Validate Password
I need a javascript, that will validate my password, to see if it is alphanumeric, before submitting. I have searched all over, please help.
Thanks.
-
Nov 3, 2002, 17:09 #2
- Join Date
- Nov 2002
- Posts
- 423
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Password validation
The easiest way to accomplish this is with regular expressions. The code below will check if the password is between 6 and 10 characters and if it's alphanumeric:
<script language="javascript">
function validatePassword(sPassword){
var re = /^[A-Za-z0-9]{6,10}$/;
if (!re.test(sPassword)){
alert("Please enter a valid password!");
}else{
alert("The password you enter is valid!");
}
}
</script>
<form name="MainForm" method="GET">
<table>
<tr>
<td align="right" class="main">Password/td>
<td class="main"><input type="password" name="txtPassword"></td>
</tr>
<tr>
<td align="right" class="main"> </td>
<td class="main"><input type="button" value="Validate Password" onclick="validatePassword(this.form.txtPassword.value)"></td>
</tr>
</table>
</form>
-
Nov 3, 2002, 17:33 #3
- Join Date
- Sep 2002
- Location
- Canada
- Posts
- 2,087
- Mentioned
- 1 Post(s)
- Tagged
- 1 Thread(s)
thanks. Just want I needed.
-
Nov 3, 2002, 18:07 #4
- Join Date
- Sep 2002
- Location
- Canada
- Posts
- 2,087
- Mentioned
- 1 Post(s)
- Tagged
- 1 Thread(s)
one more thing, if you have the time, how would I make it validate, an email feild, for example, it has to contain @ and a period.
-
Nov 3, 2002, 19:37 #5
Client side validation is great, but note that yo should never rely on it. A proper server side validation is a must.
-
Nov 4, 2002, 08:17 #6
- Join Date
- Nov 2002
- Posts
- 423
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Email validation
Here is the email validation function
function validateEmail(strEmail){
re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
return re.test(strEmail);
}
Bookmarks