I get many registrations on my site from users who use disposable mailboxes just so that they can download free stuff.
Is there any way i can add some kind of javascript validation on the register page email textbox so that it prevents users to type specific email domains?
This way i can block users from entering disposable mailboxes.
Can anyone please help me with a javascript in which i can define my blog email domain names and it gives an error to user if anyone type those domain names?
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: "");" is not valid at the start of a code block. Only identifiers, keywords, comments, "(" and "{" are valid.
Source Error:
Line 16: var idx1 = me.value.indexOf("@");
Line 17: if(idx1>-1){
Line 18: var splitStr = me.value.split("@");
Line 19: var sub = splitStr[1].split(".");
Line 20: if(domains.indexOf(sub[0])>-1){
Using this code as-is (on asp. mvc view):
<script>
var domains = ["google","msn","yahoo"]; //update ur domains here
function validateDomain(me){
var idx1 = me.value.indexOf("@");
if(idx1>-1){
var splitStr = me.value.split("@");
var sub = splitStr[1].split(".");
if(domains.indexOf(sub[0])>-1){
me.value="";
alert("invalid email");
}
}
}
</script>
<script>
var domains = ["google","msn","yahoo"]; //update ur domains here
function validateDomain(me){
var idx1 = me.value.indexOf("@@");
if(idx1>-1){
var splitStr = me.value.split("@@");
var sub = splitStr[1].split(".");
if(domains.indexOf(sub[0])>-1){
me.value="";
alert("invalid email");
}
}
}
</script>
Member
84 Points
1516 Posts
Any javascript validation to restrict specific email domain names from entering?
Nov 29, 2016 01:08 PM|jeffcarter|LINK
I get many registrations on my site from users who use disposable mailboxes just so that they can download free stuff.
Is there any way i can add some kind of javascript validation on the register page email textbox so that it prevents users to type specific email domains?
This way i can block users from entering disposable mailboxes.
My email input field looks like this:
Can anyone please help me with a javascript in which i can define my blog email domain names and it gives an error to user if anyone type those domain names?
All-Star
15186 Points
3888 Posts
Re: Any javascript validation to restrict specific email domain names from entering?
Nov 29, 2016 02:21 PM|raju dasa|LINK
Hi,
Check this code:
or, check demo here: https://jsbin.com/nupoyurudi/edit?html,js,output
rajudasa.blogspot.com || rajudasa-tech
Member
84 Points
1516 Posts
Re: Any javascript validation to restrict specific email domain names from entering?
Nov 29, 2016 02:45 PM|jeffcarter|LINK
Thank you so much for the code.
Just need an advise - do you think this is the best approach from restricting users from using disposable mailboxes and not their valid emails?
Member
84 Points
1516 Posts
Re: Any javascript validation to restrict specific email domain names from entering?
Nov 29, 2016 02:48 PM|jeffcarter|LINK
I am getting error:
Using this code as-is (on asp. mvc view):
All-Star
15186 Points
3888 Posts
Re: Any javascript validation to restrict specific email domain names from entering?
Nov 29, 2016 03:06 PM|raju dasa|LINK
Hi,
MVC Razor engine tries to parse the words starting with @, so in your case you have to escape @.
try using @@ instead of @.
rajudasa.blogspot.com || rajudasa-tech
Member
84 Points
1516 Posts
Re: Any javascript validation to restrict specific email domain names from entering?
Nov 29, 2016 03:10 PM|jeffcarter|LINK
This is not validating anything :(
All-Star
15186 Points
3888 Posts
Re: Any javascript validation to restrict specific email domain names from entering?
Nov 29, 2016 03:11 PM|raju dasa|LINK
Hi,
Please check my code again, your input control need to be added with:
rajudasa.blogspot.com || rajudasa-tech
Member
84 Points
1516 Posts
Re: Any javascript validation to restrict specific email domain names from entering?
Nov 29, 2016 03:18 PM|jeffcarter|LINK
I am sorry for the incorrect info but the register textbox is actually like this in my view (below) - i provided you the inspected html by mistake.
All-Star
15186 Points
3888 Posts
Re: Any javascript validation to restrict specific email domain names from entering?
Nov 29, 2016 03:30 PM|raju dasa|LINK
Hi,
If you are using jquery, add this extra function:
check the site for code and demo: https://jsbin.com/nupoyurudi/edit?html,js,output
rajudasa.blogspot.com || rajudasa-tech
Member
84 Points
1516 Posts
Re: Any javascript validation to restrict specific email domain names from entering?
Nov 29, 2016 05:05 PM|jeffcarter|LINK
Hi Raju,
In the view, I only have this:
In your example, you are using this which I don't have in the view page so way to add onblur in html for me.
All-Star
15186 Points
3888 Posts
Re: Any javascript validation to restrict specific email domain names from entering?
Nov 29, 2016 06:15 PM|raju dasa|LINK
Hi,
Just blindly copy/paste this function below validateDomain() function and give it a try.
rajudasa.blogspot.com || rajudasa-tech
Member
84 Points
1516 Posts
Re: Any javascript validation to restrict specific email domain names from entering?
Nov 29, 2016 06:31 PM|jeffcarter|LINK
Ok so I create a separate JS file with this:
Using this as reference in my view:
I get error:
Member
84 Points
1516 Posts
Re: Any javascript validation to restrict specific email domain names from entering?
Nov 30, 2016 04:24 AM|jeffcarter|LINK
Hi raju, any help plz?
I have tried your code several time in my view page but it is still not working?
Member
84 Points
1516 Posts
Re: Any javascript validation to restrict specific email domain names from entering?
Nov 30, 2016 04:28 AM|jeffcarter|LINK
I even tried inspecting the page so that I can provide you as much info - see below:
All-Star
18815 Points
3831 Posts
Re: Any javascript validation to restrict specific email domain names from entering?
Nov 30, 2016 07:18 AM|Nan Yu|LINK
Hi jeffcarter,
"me.value" is undefined ,Please modify your code as:
Best Regards,
Nan Yu