clearing a text box after info is entered and saved

New Here ,
Feb 08, 2019 Feb 08, 2019

Copy link to clipboard

Copied

On a information form I am creating I put in a custom script - see below to make the text box email only and an alert come up for the user to enter only a valid email address.

var alert1 = ("Please enter your email in a valid format"); var email = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;if(!email.test(event.value)){event.rc = false;app.alert(alert1);event.value = "example\u0040example.com";}

This part works, but after it is saved by the user, or even if user tabs tries to clear the box before saving it will not clear so another email

can be entered by another user filling out the form. Help!

TOPICS
Acrobat SDK and JavaScript, Windows

Views

94

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
community guidelines

correct answers 1 Correct Answer

Adobe Community Professional , Feb 08, 2019 Feb 08, 2019
There are two issues with your code:1. You're not allowing an empty value, so the field can't be cleared.2. You can't both set the event.value to something and event.rc as false. They contradict each other.Use this code instead:var alert1 = ("Please enter your email in a valid format");var email = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;if (event.value && !email.test(event.value)){    event.value = "example@example.com";    app.alert(alert1);}

Likes

Translate

Translate
Adobe Community Professional ,
Feb 08, 2019 Feb 08, 2019

Copy link to clipboard

Copied

There are two issues with your code:

1. You're not allowing an empty value, so the field can't be cleared.

2. You can't both set the event.value to something and event.rc as false. They contradict each other.

Use this code instead:

var alert1 = ("Please enter your email in a valid format");

var email = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;

if (event.value && !email.test(event.value)){

    event.value = "example@example.com";

    app.alert(alert1);

}

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
community guidelines
New Here ,
Feb 08, 2019 Feb 08, 2019

Copy link to clipboard

Copied

LATEST

Thank you so much! It is seems to be working now.

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
community guidelines