The CreatorCon Call for Content is officially open! Get started here.

How restrict # and * characters in single line text field

Gamarawaji
Giga Contributor

Hi,

i need to restrict #, * characters in a single line text field , can someone help me?

 

Thanks.

8 REPLIES 8

Community Alums
Not applicable

Hi @Gamarawaji ,

Glad to see my answer helped you, Kindly mark the answer as Correct & Helpful both such that others can get help.

Thanks,
Sandeep

Ankur Bawiskar
Tera Patron
Tera Patron

@Gamarawaji 

If #,* are not allowed then what else is allowed?

based on that you can create RegEx

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

only #and * are not allowed and the rest can be accepted.

 

Thank You.

Kartik Sethi
Tera Guru

Hi @Gamarawaji 

 

You need to create an onChange Client Script -

  • Field Name (Variable Name in case of Catalog Items): Your field/variable name
  • Script:
    function onChange(control, oldValue, newValue, isLoading, isTemplate) {
        if (isLoading || newValue === '') {
            return;
        }
    	
    	//Hide all messages if any
    	g_form.hideAllFieldMsgs();
    	
    	var testNameRegex = /^.+.(\*|#)+.+.$/;
    	
    	//Test the RegEx; If * or # is found then true else false
    	if(testNameRegex.test(newValue)) {
    		//Error message goes here
    	} else {
    		//Add required logic or remove else loop if not required
    	}
    }​

     

Please try the above code and let me know if you still face any issue.

 


Please mark my answer as correct if this solves your issues!

If it helped you in any way then please mark helpful!

 

Thanks and regards,

Kartik