Skip to main content
rakeshk21205956
Inspiring
Mar 13, 2018 9:44 AM UTC
Answered

script to find a character in text field and see if it is not repeated

I have text field  say TEXT1  which can type anything from numbers to strings to special character.

My requirement is  what if i want some specific character to be input only once.

for example if want that user can use  the character "a" (not case sensitive) only once.

i used the following script but didnot work

if(!this.getField("TEXT1").contains("a")){

this.getField("TEXT1").value = this.getField("TEXT1").valueAsString + "a";

}

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Mar 13, 2018 1:29 PM UTC

if(["a"].test(this.getField("Text18").value) == false){

this.getField("Text18").value = this.getField("Text18").valueAsString + "a";

}

i modified your script to something above but still not working


Change the first line to:

if(/a/.test(this.getField("Text18").valueAsString) == false){

12 replies

try67
Community Expert
Community Expert
Mar 13, 2018 9:56 AM UTC

How do you want it to work, exactly? Do you want to block the user from typing a character that already appears in the field?

Or do you want to reject the value when then leave it? Something else?

Translate
rakeshk21205956
Inspiring
Mar 13, 2018 10:08 AM UTC

i want that specific character doesnot appear twice in that text field.. in above example say  "a"   although they can write anything except for "a" (not more than once).... the value already entered donot have to discarded.... .. like i wrote  " I have  a dog.."    since it contains two "a"  .....   it should write something like this..... .

"I have dog"  i.e when the users presses 'a" again it should not work ... although other keys should work and they can continue without discarding the previous value .

Translate
try67
Community Expert
Community Expert
Mar 13, 2018 11:34 AM UTC

Use this code as the field's custom Keystroke event:

if (event.change) event.rc = event.value.indexOf(event.change)==-1;

Translate