Monday, March 23, 2009

Regular expression for a Foramt 'XX99999X'

function validationForXYZ()
{

var iKeyCode,strKey;
if(window.event)
iKeyCode = window.event.keyCode;

if ((iKeyCode > 96) && (iKeyCode < keycode =" iKeyCode-32;" ikeycode =" window.event.keyCode;" strkey =" String.fromCharCode(iKeyCode);" obj =" document.getElementById('txtAgencyCIN');" value =" obj.value.toUpperCase();" xyzval =" obj.value" validchars =" /^[A-Z]{1,2}$/;">=3) && (XYZVal.length <= 7)) //checking next 5 chars of numbers
validChars = /^[A-Z]{2}[0-9]{1,5}$/;
else if (XYZVal.length ==8)
validChars = /^[A-Z]{2}[0-9]{5}[A-Z]$/; //again last two if chars
else
return false;
if(!validChars.test(XYZVal))
{
alert("Invalid XYZ format: If present, it must be 8 characters in the format: 'XX99999X'. (eg. AB74819R)");
return false;
}

}

No comments: