Skip to main content
Participant
Feb 8, 2019 2:48 PM UTC
Answered

clearing a text box after info is entered and saved

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!

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Feb 8, 2019 3:17 PM UTC

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

}

2 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
Feb 8, 2019 3:17 PM UTC

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

}

Translate
Participant
Feb 8, 2019 3:53 PM UTC

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

Translate