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!
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);
}
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);
}
Copy link to clipboard
Copied
Thank you so much! It is seems to be working now.