Click to See Complete Forum and Search --> : Validation


ctwista
09-30-2003, 04:52 AM
Can anyone help me with the code for validating a password that has to include a special character and a number, otherwise an alert is displayed.

Thanks

Charles
09-30-2003, 05:04 AM
Assuming the special character is "#"...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>

<style type="text/css">
<!--
label {display:block; margin:1em 0em}
input {display:block}
-->
</style>

<form action="">
<div>
<label>User Name<input type="text"></label>
<label>Password<input type="password" onchange="if (!/[\d\#].*[\d\#]/.test(this.value)) {alert('That does not appear to be a valid password.'); this.value=''; this.focus()}"></label>
<button type="submit">Submit</button>
</div>
</form>