RichardH123
Programmer
I am trying to validate a form field. The field can have a maximum of 4 characters. The first character is always the letter 'A', the fourth character can be either the letter 'A' or the letter 'B' but nothing else. I also need a mask on the field like this A _ _ _
I have this code, but I am now stuck. Any help with this is much appreciated.
<script language="JavaScript" type="text/javascript">
<!--
function Format(obj){
string='A _ _ _ '
val=obj.value.replace(/_/g,'');
val=val.replace(/A/g,'');
val=val.replace(/\s/g,'');
val1=''
for (zxc0=0;zxc0<val.length;zxc0++){
val1+=val.charAt(zxc0)+' ';
}
if (val1.length<0){
obj.value=val1+string.substring(val1.length,string.length);
}
else{
val2=val1.substring(0,0)+'A '+val1.substring(6,0);
obj.value=val2+string.substring(val2.length,string.length);
}
}
//-->
</script>
I have this code, but I am now stuck. Any help with this is much appreciated.
<script language="JavaScript" type="text/javascript">
<!--
function Format(obj){
string='A _ _ _ '
val=obj.value.replace(/_/g,'');
val=val.replace(/A/g,'');
val=val.replace(/\s/g,'');
val1=''
for (zxc0=0;zxc0<val.length;zxc0++){
val1+=val.charAt(zxc0)+' ';
}
if (val1.length<0){
obj.value=val1+string.substring(val1.length,string.length);
}
else{
val2=val1.substring(0,0)+'A '+val1.substring(6,0);
obj.value=val2+string.substring(val2.length,string.length);
}
}
//-->
</script>