Skip to main content
Participant
February 8, 2019
Answered

clearing a text box after info is entered and saved

  • February 8, 2019
  • 1 reply
  • 660 views

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

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

}

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
February 8, 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);

}

Participant
February 8, 2019

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