Home › Forums › General discussion › Email format check in text field
- This topic has 5 replies, 2 voices, and was last updated 4 years, 5 months ago by Alexander Bautz.
-
AuthorPosts
-
-
June 12, 2020 at 19:40 #30647
Hi all,
I have a free-type text field for users to enter an email address, but as you know, people get it wrong. The text field allows users to enter multiple email addresses, but they are required to separate them with a semicolon. They get this wrong too.
I need to be able to correct the format for users if they get it wrong, for example:
“name @comany.com” – space in the email address (remove space)
“name@comany.com other@comany.com” – no semicolon separating email addresses (place a semicolon separating all email addresses)
“name @comany.com other@comany.com” – both, space in the email and no semicolonIs there a way to correct this for users as they type or maybe when a submit button is pressed?
Many thanks
-
June 12, 2020 at 20:02 #30649
You can try adding something like this to your Custom JS:
jQuery("#dffs_YOUR_MULTILINE_FIELD_INTERNAL_NAME textarea").on("blur", function(){ var val = jQuery(this).val(); if(val.split(" ").length > 1){ spjs.dffs.alert({ "title": "Error in email address", "msg": "You have one or more spaces in your email addresses - please correct" }); } }).on("keyup", function(){ var val = jQuery(this).val(); if(val.split(" ").length > 0){ jQuery(this).val(val.split(" ").join(";")); } });
Replace YOUR_MULTILINE_FIELD_INTERNAL_NAME with your field internal name.
Alexander
-
June 12, 2020 at 20:16 #30651
Thanks Alexander,
The text field is a Single line of text, but I guess I could convert it into multiline.
I was using this so far:
//remove spaces from email addresses
jQuery(“#dffs_Title input”).on(“keyup”,function(e){
var str = jQuery(this).val();
jQuery(this).val(str.replace(‘ ‘, ” ));
});It will not allow users to enter any spaces but when it comes to separating email addresses, users will likely leave two email addresses merged together when they decide to use a space and not semicolon, and without looking.
I know this one could be very tricky.
-
June 13, 2020 at 08:00 #30653
In my code example you can just change textarea to input.
The snippet I provided above will trim spaces as you write, and also alert in case you paste content (right click > paste) with space in the field.
Alexander
-
June 22, 2020 at 11:15 #30719
Thanks Alexander, it work’s great, however no alert is displayed for some reason.
I tried with several spaces and different combinations. All spaces are replaced with semicolon, which is fine, but no alert 🙁-
June 22, 2020 at 15:10 #30721
In this example it only alerts if you PASTE the contents using right click > paste. If you use Ctrl + v the keyup functionality will remove the space immediately.
Alexander
-
-
-
AuthorPosts
- You must be logged in to reply to this topic.