Jump to content

js expert, pls help!


bong_hong26

Recommended Posts

How do i make change on the Offer ID's digits of the numbers and numbers of letter? Offer ID contains:###A (exp: 407F)#AA (exp: 5JA)#AA# (exp: 5JA1)
{	var errmsg = new String("");	if (document.OrderForm.a_Offer_ID.value.length <= 0 ) {		errmsg = errmsg + "\n" + "Required Field is missing: Zonet Rebate Offer ID";		document.OrderForm.a_Offer_ID.focus();		alert (errmsg);		return false;	} 		var OfferIDPat = /^[0-9]{3}[a-zA-Z]{2}$/	var matchArray=document.OrderForm.a_Offer_ID.value.match(OfferIDPat)	if (matchArray==null) {			errmsg = errmsg + "\n" + "Zonet Rebate OfferID format #AA (ie. 5JA)";		document.OrderForm.a_Offer_ID.focus();		alert (errmsg);		return false;
Link to comment
Share on other sites

If I understand your post this should work, you'll need to test all your variations.

<script type="text/javascript">function ckField(){var errmsg = '';var OfferIDPat = /^[0-9]{1,3}[a-z]{1,2}[0-9]? \(exp: [0-9]{1,3}[a-z]{1,2}[0-9]?\)$/i;var matchArray=document.OrderForm.a_Offer_ID.value.match(OfferIDPat);    if (matchArray==null) {    errmsg = errmsg + "\n" + "Zonet Rebate OfferID format #AA (ie. 5JA)";    document.OrderForm.a_Offer_ID.focus();    alert (errmsg);    return false;    }return true;    }</script>

Post back if you need more help.Thanks,

Link to comment
Share on other sites

Thanks!It does take the below Offer ID Format :###A (exp: 407F)#AA (exp: 5JA)#AA# (exp: 5JA1)Another problem is that i've also tested with 55555 or 5aaa5... etc., it seems to be able to take EVERYTHING!! What to do wat to do? Thanks in advance for answering my questions!

Link to comment
Share on other sites

Testing doesn't indicate that for me, 55555 and 5aaa5 both fail.Ideally the "test()" method should be used though:

<html><head><script type="text/javascript">function ckField(){var errmsg = '';var OfferIDPat = /^[0-9]{1,3}[a-z]{1,2}[0-9]? \(exp: [0-9]{1,3}[a-z]{1,2}[0-9]?\)$/i;   if (!OfferIDPat.test(document.OrderForm.a_Offer_ID.value)) {   errmsg = errmsg + "\n" + "Zonet Rebate OfferID format #AA (ie. 5JA)";   document.OrderForm.a_Offer_ID.focus();   alert (errmsg);   return false;   }return true;    }</script></head><body><form name="OrderForm" onsubmit="return ckField()"><input type="text" name="a_Offer_ID" size="20" /><br /><input type="submit"></form></body></html>

Try this page and let us know how it works out.You also want to make sure your javascript is enabled :)Thanks,

Link to comment
Share on other sites

Well, how about we check for 2 leading digits with a second regular expression?

<script type="text/javascript">function ckField(){var errmsg = '';var IDPat =  /^[0-9]{1,3}[a-z]{1,2}[0-9]? \(exp: 407F\)| \(exp: 5JA\)| \(exp: 5JA1\)$/i;//test for 2 leading digitsvar _IDPatFail = /^[0-9]{2}[a-z]{1,2}/i;  if (!IDPat.test(document.OrderForm.a_Offer_ID.value) ||       _IDPatFail.test(document.OrderForm.a_Offer_ID.value)) {  errmsg = errmsg + "\n" + "Zonet Rebate OfferID format #AA (ie. 5JA)";  document.OrderForm.a_Offer_ID.focus();  alert (errmsg);  return false;  }return true;    }</script>

Thanks,

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...