Highlighted

Only numbers in a text field, otherwise app alert

Community Beginner ,
Nov 12, 2020

Copy link to clipboard

Copied

Hello!

I am in the process of creating a form and I have already found something that prevents input, for example if I only want numbers in a textfield:

if (event.change) {

event.rc = /^[0-9,\.\(\)]+$/.test(event.change);
}



But how can I add that an error message appears when the user enters a letter?

TOPICS
PDF forms

Views

49

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

Only numbers in a text field, otherwise app alert

Community Beginner ,
Nov 12, 2020

Copy link to clipboard

Copied

Hello!

I am in the process of creating a form and I have already found something that prevents input, for example if I only want numbers in a textfield:

if (event.change) {

event.rc = /^[0-9,\.\(\)]+$/.test(event.change);
}



But how can I add that an error message appears when the user enters a letter?

TOPICS
PDF forms

Views

50

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
Nov 12, 2020 0
Engaged ,
Nov 13, 2020

Copy link to clipboard

Copied

See if this works for you:

as "Custom Validation Script" enter:

var abc = /^[0-9]+$/;
if(event.value.match(abc)|| event.value == "");
else app.alert("Enter number please.");

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...
Nov 13, 2020 0
Community Beginner ,
Nov 13, 2020

Copy link to clipboard

Copied

Thank you very much, but if I put this on Custom Validation Script and let my script in on Format Customer Keystroke. I can't enter any alpha characters. If I remove it, and use your script, then the alpha characters appears also I get the alert.
But I want prevent 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...
Nov 13, 2020 0
Contributor ,
Nov 13, 2020

Copy link to clipboard

Copied

What exactly are you trying to prevent?User to enter letters? Your code will do that already.

But how can I add that an error message appears when the user enters a letter?

They can't enter letter with your code so there is no need for alert.

If you want users to alert when they enter letter use Nesa's code and remove yours.

 

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...
Nov 13, 2020 1
Engaged ,
Nov 13, 2020

Copy link to clipboard

Copied

This will give you alert and delete letter when input:

var abc = /^[0-9]+$/;
if(!event.value.match(abc)){
app.alert("Enter number please.")
event.value = "";}

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...
Nov 13, 2020 1
D.Özel LATEST
Community Beginner ,
Nov 13, 2020

Copy link to clipboard

Copied

Perfect, thank you!

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...
Nov 13, 2020 0