Skip to main content
rakeshk21205956
Inspiring
March 13, 2018
Answered

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

  • March 13, 2018
  • 1 reply
  • 1107 views

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 has been closed for replies.
Correct answer try67

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){

1 reply

try67
Community Expert
Community Expert
March 13, 2018

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?

rakeshk21205956
Inspiring
March 13, 2018

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 .

try67
Community Expert
Community Expert
March 13, 2018

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

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