By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,253 Members | 1,689 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,253 IT Pros & Developers. It's quick & easy.

Format of textfield of livecycle designer

P: 2
Hi there. I got the following script for the format of an inputted number (7 spaces). If entered as "1" the format will be changed to "0000001". Now I want to get this effect: if entered as "f1", the format will be changed to "F0000001". How can modify the script to achieve that? Thanks.

Expand|Select|Wrap|Line Numbers
  1. if (!(this.isNull)) {
  2. var tf = this.rawValue;
  3. if (tf < 1 ) {
  4."The number must be a numeral starting from 1.","Incorrect Number",1);
  5."TextField27"); }
  6. if (tf.length < 7) {
  7. var diff = 7 - tf.length;
  8. for (var i=0;i < diff;i++) {
  9. tf = "0" + tf;}
  10. this.rawValue = tf;}
  11. var regExp = /\d{7}/;//}
  12. if (!(regExp.test(tf))) {
  13."The number must be in the format of 9999999.","Validation",1);
  14. this.rawValue = "";
Nov 9 '11 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 15k+
P: 16,027
Would this be for the same field or for a different field? In other words, do you want to allow both formats in the same field or this is to apply to a different field?

In any case, lines 6-10 change the format from 1 to 0000001. The exact change would depend on the above question. You'd check for a length of 8 instead of 7 and separate the F and then use the same code.
Nov 9 '11 #2

P: 2
Hi acoder, Thanks for your reply. What I intend to do is providing user with a 8-character textfield for input. If user inputs "f1" or "f01" or similar entry, the display of the relevant textfield will be "F0000001". If the first character of the input is anything other than "f" or "F" or 0-9, it will prompt user with an error message. Can you please advise me how to modify my code to that effect. Thanks in advance.
Nov 10 '11 #3

Expert Mod 15k+
P: 16,027
The problem here is that I'm not familiar with the exact syntax to use in LiveCycle's version of JavaScript. If you can find the code/function/method to get the character at a certain position, it should be easier to solve.

Here's a link to the documentation which should help:

You have 2 issues:
1. formatting
2. error checking

Error checking should be relatively straightforward with a regular expression, e.g. you could use something like:
Expand|Select|Wrap|Line Numbers
  1. var regExp = /^[fF]?\d{7}$/;
(not tested)

For the formatting, read the documentation to get the first character which you should check for either F or a number. Then you can split it off and add it back on after adding the required number of 0s.
Nov 10 '11 #4

Post your reply

Sign in to post your reply or Sign up for a free account.