Validate phone number

Hello, I was wondering is there any way to validate phone fields in Notes, something like:

Phone# : h1 - h2 -h3

I would like h1 only hold 3 digits, if use clicks more than 3 digits,it goes to h2 automatelly, h2 only hold 3 digits as well, h3 hold 4 digits.

Thanks a lot for any help.

Linda

Subject: Validate phone number.

h1, h2, and h3 are all fields, I assume.

I would use the onChange javascript event to check the value of the fields. If the value entered is not a number, restore the previous value (or just clear the field). Once a sufficient number of digits have been entered for each field use the focus method to set focus to the next field. You will probably want to code something in the onBlur event to make sure the user does not tab out of the field before completely filling it with appropriate values.

Subject: RE: Validate phone number.

Hi Cesar,

Thanks for your reply.

Would you please put the detail coding? Thanks a lot!

Linda

Subject: RE: Validate phone number.

OK, this will probably work:

In the JS Header, add the following code:

//=======================================

var fieldvalues = new Array();

var thisForm;

function validateNumber(fld, maxNumber, nextFld) {

var onlyNumbers = fld.value.replace(/([^0-9])/g, '');

fld.value = onlyNumbers;



var match = /([0-9]+)/i.exec(fld.value);

if(match[1].length == maxNumber) {

	nextFld.focus()

}

}

//=======================================

Then, for each field h1, h2 , and h3, add the following code:

For h1:

//=======================================

onBlur:

validateNumber(this, 3, thisForm.h2);

onChange:

validateNumber(this, 3, thisForm.h2);

onFocus:

fieldvalues[this.name] = this.value;

onKeyUp:

validateNumber(this, 3, thisForm.h2);

//=======================================

For h2:

//=======================================

onBlur:

validateNumber(this, 3, thisForm.h3);

onChange:

validateNumber(this, 3, thisForm.h3);

onFocus:

fieldvalues[this.name] = this.value;

onKeyUp:

validateNumber(this, 3, thisForm.h3);

//=======================================

For h3:

//=======================================

onBlur:

validateNumber(this, 4, thisForm.h1);

onChange:

validateNumber(this, 4, thisForm.h1);

onFocus:

fieldvalues[this.name] = this.value;

onKeyUp:

validateNumber(this, 4, thisForm.h1);

//=======================================

Note that for h3, rather than cycling back to h1 on successful validation, change

thisForm.h1

to

thisForm.NextTargetField

Subject: RE: Validate phone number.

Hi Cesar, I am soryy for reply late, Thank you very much for your help.

I will let you know how’s it going once I add the coding to my database.

Once again, thanks a lot.

Linda

Subject: RE: Validate phone number.

Hi Cesar,

I put the coding to the events as you told. When I open the document, there is an error pop up window"ValidateNumber is not defined".

Can I ask how to fix it?

Thanks a lot for you help.

Linda

Subject: RE: Validate phone number.

The function is named validateNumber and not ValidateNumber (note the case sensitivity of the “v”)

Subject: RE: Validate phone number.

Hello Cesar, Sorry, I checked the coding, it is “v”, not “V”

I just copy and paste your code to my application. I was wondering why it shows the error message.

Thank you very much for your reply quickly.

Actually, I am waiting your response.

Many many thanks for your help.

Linda

Subject: RE: Validate phone number.

Sorry - my mistake - I forgot to post the code that goes into the onload event…

//=========================

thisForm = window.document.forms[0];

//=========================

…although this should not likely be the source of the problem you are having.

Are you running this code in Web or on Client? Have you set the code Run to the appropriate client?

Subject: RE: Validate phone number.

Hi Cesar, I run the coding in Notes, is it will be a problem?

I put “thisForm = window.document.forms[0];” on the form onload event, there is still a error message as befor.

Thanks.

Linda

Subject: RE: Validate phone number.

Not sure - I tested in web. Although one of the events (namely onKeyUp) only works in Web and not in Notes. Unfortunately, this is the one that will trigger jumping to the next field. The problem with JavaScript in the Notes Client is that Notes doesn’t register a change in the field until you move out of it (for editable fields) - it does not register a change each time you type a character and this is really what you are looking for.

Subject: RE: Validate phone number.

Hi Cesar, Thanks for your details information. I see. “it does not register a change each time you type a character and this is really what you are looking for.” that’s I wanted to know. It works for Web, but Notes.

I guess I need to use formula to do it.

Thank you so much for all your help and for your time. ^-^

Linda