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

Allen Andreas
Administrator
Administrator

Hello,

There's several ways to do this, but you can create onChange client script that simply looks at that field to validate, such as:

var string = g_form.getValue('field_name');
if (string.indexOf("#") > -1 || string.indexOf("*") > -1) {
alert("Please do not use the # or * characters");
g_form.clearValue('field_name');
}

You can also use regex, etc.

You did not state if this was a variable or not, thus I didn't mention anything regarding variable regex specifically. My method above will work, as well as reviewing the use of basic regex as well will work.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi,

 

the above mentioned code snippet is not working so can you share a regex for this case(like excluding # and *).

 

Thanks.

Hello,

The above mentioned code does work. You should use it in an onChange client script, choosing the correct field to execute on...and it works just fine:

find_real_file.png

find_real_file.png

You can certainly give me more feedback and an example of how you're trying to use it, but please don't imply that what I've offered doesn't work, when it does.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Community Alums
Not applicable

Hi @Gamarawaji ,

Variable Regex should help you.

Here is a thread which has 2 approaches along with the code :https://community.servicenow.com/community?id=community_question&sys_id=f3fde89bdbb9c8905ed4a851ca96...

Mark my answer correct & Helpful, if Applicable.

Thanks,
Sandeep