RegEx test and change to uppercase

Explorer ,
Mar 19, 2019

Copy link to clipboard

Copied

Hi there,

Please can some one help me.

I've been playing around with custom keystroke scripts and all has gone ok so far apart from this variation.

I have a text field that has a RegEx test to allow only character 0-9, a-z & A-Z.

Here's the code:

var r = new RegExp("^[0-9a-zA-Z]*$");

var result = r.test(event.change);

if (result == true) {console.println("Here - stage 1 true")} else {console.println("Here - stage 1 false")};

if ( result != true )

{

    event.change = "";

    console.println("Here - stage 2 false");

} else {

    event.change.toUpperCase();

    console.println("Here - stage 2 true");

}

What I'm trying to do with this one is allow the user to enter characters 0-9, a-z & A-Z.

However, if the user enters any lowercase letter I'm trying to change it toUpperCase().

So far I've not succeeded with this

Thanks for the help.

After a little playing around I managed to condense everything to 2 lines.

var r = new RegExp("^[0-9a-zA-Z]*$");

if (r.test(event.change)) {event.change = event.change.toUpperCase()} else {event.rc = false};

This seems to do the trick.

TOPICS
Acrobat SDK and JavaScript, Macintosh

Views

230

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

RegEx test and change to uppercase

Explorer ,
Mar 19, 2019

Copy link to clipboard

Copied

Hi there,

Please can some one help me.

I've been playing around with custom keystroke scripts and all has gone ok so far apart from this variation.

I have a text field that has a RegEx test to allow only character 0-9, a-z & A-Z.

Here's the code:

var r = new RegExp("^[0-9a-zA-Z]*$");

var result = r.test(event.change);

if (result == true) {console.println("Here - stage 1 true")} else {console.println("Here - stage 1 false")};

if ( result != true )

{

    event.change = "";

    console.println("Here - stage 2 false");

} else {

    event.change.toUpperCase();

    console.println("Here - stage 2 true");

}

What I'm trying to do with this one is allow the user to enter characters 0-9, a-z & A-Z.

However, if the user enters any lowercase letter I'm trying to change it toUpperCase().

So far I've not succeeded with this

Thanks for the help.

After a little playing around I managed to condense everything to 2 lines.

var r = new RegExp("^[0-9a-zA-Z]*$");

if (r.test(event.change)) {event.change = event.change.toUpperCase()} else {event.rc = false};

This seems to do the trick.

TOPICS
Acrobat SDK and JavaScript, Macintosh

Views

231

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Mar 19, 2019 0
Explorer ,
Mar 19, 2019

Copy link to clipboard

Copied

Think I've solved it.

The appears to work:

var r = new RegExp("^[0-9a-zA-Z]*$");

var result = r.test(event.change);

if ( result != true )

{

    event.change = "";

} else {

    event.change = event.change.toUpperCase();

}

P.S.     Here's another question... how do I format my code correctly for this forum?

          Thanks.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 19, 2019 0
Most Valuable Participant ,
Mar 19, 2019

Copy link to clipboard

Copied

To reject the entered value you should use this code:

event.rc = false;

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 19, 2019 0
Explorer ,
Mar 20, 2019

Copy link to clipboard

Copied

Thanks for the help.

After a little playing around I managed to condense everything to 2 lines.

var r = new RegExp("^[0-9a-zA-Z]*$");

if (r.test(event.change)) {event.change = event.change.toUpperCase()} else {event.rc = false};

This seems to do the trick.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 20, 2019 0
Most Valuable Participant ,
Mar 20, 2019

Copy link to clipboard

Copied

Great job!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 20, 2019 1
Explorer ,
Mar 20, 2019

Copy link to clipboard

Copied

Thanks!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 20, 2019 0
Explorer ,
Mar 20, 2019

Copy link to clipboard

Copied

Just another quick question that's come to mind.

I've implemented this as a 'Custom Keystroke Script'.

Should the code above have a if(!event.willCommit) at the start?

If the keystrokes are being formatted with this method is the if(!event.willCommit) necessary?

Thanks.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 20, 2019 0
Most Valuable Participant ,
Mar 20, 2019

Copy link to clipboard

Copied

I don't think you need it.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 20, 2019 0
Explorer ,
Mar 20, 2019

Copy link to clipboard

Copied

Thanks for the reply and help.

The question popped up because I've seen a few examples with it in.

Thanks again.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 20, 2019 0
Adobe Community Professional ,
Mar 20, 2019

Copy link to clipboard

Copied

how do I format my code correctly for this forum?

Capture_4.jpg

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 20, 2019 1
Explorer ,
Mar 20, 2019

Copy link to clipboard

Copied

Great, thanks for the help.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 20, 2019 0