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

Hi christopherperry,

 

Thanks for the response 

 

It is not string type field it is a variable in catalog item for onboard form 

I need to populate error if they enter more than 15 characters

Can you please help me on this script?

 
Thanks in Advance!!

 

Yousaf
Giga Sage

Hi Hemanth,

Please try,

function onSubmit() {

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

 

Mark Correct and Helpful if it helps.


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

hemanth16
Tera Contributor

Hi Yousaf,

Thanks for the script,

Is it possible to calculate first name field and last name field and show the error if it is more than 15 characters?

Thanks in Advance!!

hemanth you mean the total of both fields?

first name + last name should not be greater than 15?


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

hemanth16
Tera Contributor

Hi Yousaf,

 

Yes first name + last name should not be greater than 15?