Highlighted

Format Numeric Field

_Win_Lam_

15-09-2008

I format a Numeric Field with: 88/99/8888, and now i need a script to make sure that "99" is not greater than 12.



Can someone help me out on this please?

Replies

Highlighted

pguerett

16-09-2008

You can use javascript string parsing commands to parse out the next 2 chars after the 1st slash. There are many good references on the web in using javascript parsing commands.
Highlighted

_Win_Lam_

16-09-2008

Hi Paul,



Thanks for your advice. But i'm afraid i'm only an apprentice and fresh new user in regards to Javascripting and Livecycle Designer.



I'm terribly sorry but can you guide me with a script on this?



Appreciate your help....
Highlighted

pguerett

17-09-2008

Why not simply use a date control. The user would pick the date from a calendar and you woudl not have to do any checks.



Conversely use a date object would allow you to set a display and edit pattern that would match the date format you want hence having all of this done for you.



If you must go the route you are going here is a simple example of javascript that you could use:



//create a variable to hold the string

var str_temp = TextField1.rawValue;



//Test to see if the string is > 12

if (str_temp.substr(3,2) > "12"){

//The string is graeter than 12 so let the user know

app.alert("You cannot enter a value greater than 12");

//Put the cursor back in the offending field

xfa.host.setFocus("TextField1");

}



Assuming the field that holds the date is TextField1 and the code is running on some other event in the same context as TextField1.
Highlighted

_Win_Lam_

17-09-2008

Thanks Paul! I'll try it on my form.

I didn't want to use a date control is because Users here tend to enter their date of birth in the format: 19092008.



For a date-field validation, Livecycle is not able to auto-format the date into 19/09/2008 like the numeric field does. The display and edit pattern in Livecycle doesn't seem to work even when i enter a DD/MM/YYYY format as the edit and display pattern. It only alerts the Users to enter date in DD/MM/YYYY rather than to format it automatically.



Unless, if you can help me with something like an auto-format script that can transform the date to 19/09/2008 whenever Users enter DOB as 19092008.



BTW, may I know if you have an useful javascript reference to recommend where i can learn to script more effectively without all the hassle?
Highlighted

pguerett

17-09-2008

There are plenty of good references on the web. Just do a search for javascript references and you will find lots.