RichardH
11-07-2005, 03:07 AM
The code below was kindly created by vwphillips. And it works great.
However, I now need to place an exact length on this textbox of 13 characters as the field needs to be made mandatory. But because the textbox is prefilled with 25 characters I can't just state a minimum of 13. And if I state an exact length of 13 inputting into the textbox is not possible.
There also needs to be an alert box for this validation.
Thank you in advance for any help on this.
RichardH
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<script language="JavaScript" type="text/javascript">
<!--
function Format(obj){
string='_ _ _ _ # _ _ _ _ _ _ # #'
val=obj.value.replace(/_/g,'');
val=val.replace(/#/g,'');
val=val.replace(/\s/g,'');
val1=''
for (zxc0=0;zxc0<val.length;zxc0++){
val1+=val.charAt(zxc0)+' ';
}
if (val1.length<10){
obj.value=val1+string.substring(val1.length,string.length);
}
else {
val2=val1.substring(0,8)+'# '+val1.substring(8,20);
obj.value=val2+string.substring(val2.length,string.length);
}
}
//-->
</script></head>
<body>
<input value="_ _ _ _ # _ _ _ _ _ _ # #" onkeyup="Format(this);" onkeypress="Format(this);">
</body>
</html>
However, I now need to place an exact length on this textbox of 13 characters as the field needs to be made mandatory. But because the textbox is prefilled with 25 characters I can't just state a minimum of 13. And if I state an exact length of 13 inputting into the textbox is not possible.
There also needs to be an alert box for this validation.
Thank you in advance for any help on this.
RichardH
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<script language="JavaScript" type="text/javascript">
<!--
function Format(obj){
string='_ _ _ _ # _ _ _ _ _ _ # #'
val=obj.value.replace(/_/g,'');
val=val.replace(/#/g,'');
val=val.replace(/\s/g,'');
val1=''
for (zxc0=0;zxc0<val.length;zxc0++){
val1+=val.charAt(zxc0)+' ';
}
if (val1.length<10){
obj.value=val1+string.substring(val1.length,string.length);
}
else {
val2=val1.substring(0,8)+'# '+val1.substring(8,20);
obj.value=val2+string.substring(val2.length,string.length);
}
}
//-->
</script></head>
<body>
<input value="_ _ _ _ # _ _ _ _ _ _ # #" onkeyup="Format(this);" onkeypress="Format(this);">
</body>
</html>