How do I restrict a single line text field to 15 characters only?

hemanth16
Tera Contributor

Hi,

I need to restrict the first name and last name fields more than 15 letters 

Can you help me on script?

Thanks in Advance!!

1 ACCEPTED SOLUTION

Can you please try 
g_form.addErrorMessage Instead of showErrorBox.


***Mark Correct or Helpful if it helps.***

View solution in original post

17 REPLIES 17

Try I think this will work.

function onSubmit() {
var firstName = g_form.getValue('field_name').length;
var lastName = g_form.getValue('field_name').length;
var result = firstName+lastName;

    if(result > 15){
		g_form.showFieldMsg('Enter less than 15 characters ', 'error', true);
		return false;
	}
}

***Mark Correct or Helpful if it helps.***

and you can use different type of messages through scripting

Scripting alert, info, and error messages


***Mark Correct or Helpful if it helps.***

hemanth16
Tera Contributor

Hi Yousaf,

I have created onsubmit client script 

Now I am not able to submit the request and the error message also not showing!!

Please add info message before if like

g_form.addInfoMessage(result);

 


***Mark Correct or Helpful if it helps.***

hemanth16
Tera Contributor

Hi Yousaf,

I have added that add info before if 

I am not able to see the error message 

When I have given less than 15 characters i am able to submit if I am giving greater than 15 I am not able to submit but i am not able to see the error message