Copy link to clipboard
Copied
Is there a javascript to format a text field to have number format and allow text as well?
OK, then you can use this code as the field's custom Format script:
if (event.value && !isNaN(Number(event.value))) AFNumber_Format(2, 1, 0, 0, "", false);
Copy link to clipboard
Copied
Not an existing one, but you can certainly write one... The tricky part will be to differentiate between a number and other text, and only apply the formatting to the former.
Copy link to clipboard
Copied
I am a newbie to JavaScript:(
Copy link to clipboard
Copied
Is there a javascript to format a text field to have number format and allow text as well?
Below code i found can set the number format, but how to format the field to take a specific value XX. If i enter number it should be formatted in numeric format and should take the character XX as well.
this.getField("fieldname").setAction("Format", 'AFNumber_Format(0, 1, 0, 0, "", false)');
Copy link to clipboard
Copied
Do you mean that if you enter "ABC" into the field it should stay the same, but if you enter "5" it should become "5.00" or something like that?
Copy link to clipboard
Copied
Exactly!!
Copy link to clipboard
Copied
What about if it's "5 ABC 6"? Or "5ABC6"? This is not a simple task, as you can see...
Copy link to clipboard
Copied
Yeah. I need to have either number with numerical format or a text value.
Copy link to clipboard
Copied
So "5ABC6" should become "5.00ABC6.00"?
Copy link to clipboard
Copied
No. At a time it will be either text or number. If I enter 10000, it should be formatted as 10,000. At some cases I will enter NONE. Usually if I enter text in numeric field, it won’t allow.
Copy link to clipboard
Copied
OK, then you can use this code as the field's custom Format script:
if (event.value && !isNaN(Number(event.value))) AFNumber_Format(2, 1, 0, 0, "", false);
Copy link to clipboard
Copied
Yay!!!! It worked. Thank you so much!!