How to set single line text variable length?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2018 10:54 PM
How to set single line text variable length?
I want to set variable length to 20 characters.
Any one please suggest me.
- Labels:
-
Best Practices
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2018 11:13 PM
Hello, you can give them an alert saying the character limit must not exceed 20 characters and only the form gets submitted if it is less than 20.
Here is the code:
function onSubmit() {
var text = g_form.getValue("u_epic_device_haiku_canto");
var length=text.length;
if(length <40)
{
alert("Please enter full field");
return false;
}}
This is an onSubmit client script.
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-03-2023 02:07 PM
@Akash4 is it possible to include another requirement where the value must start with a specific letter? I think the if statement will be if(startsWith !=c) but don't know to properly write the lines before. And the "C" doesn't have to be case sensitive
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2018 11:19 PM
Setting character limit is not supported.
You can write a onChange client script and check if the new value is more than 20, trim it to 20 characters and show an alert..Alternatively you can also write an onSubmit client script to verify it on submission of the form.
I would suggest for onChange as it will give the message at the same time and user will be well informed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2018 11:22 PM
Hi
If the catalog item isn't used on Service Portal, you can try below code :
This code needs to be written on onLoad client script.
g_form.getControl('var_name').setAttribute('maxlength', 20);