-1

I am very new to programming. I'd like to require a school email address to login/sign up to my site, but I have no idea how to do this. I've written logins before, and email confirmations (etc), but I don't know how to require a specific email address (e.g. john@notarealcollege.edu). How would I verify & require a specific address (e.g. ".randomcollege.edu")? preferably in JS/PHP

Hugely appreciate the help, ty

LemonLime
  • 9
  • 1
  • 5
  • Search for "Regex" – Francisco Presencia Jun 05 '16 at 15:39
  • You can use regex. But unfortunately I don't know how to use them in this situation. – Ali1928 Jun 05 '16 at 15:39
  • 1
    I have ready made scripts just for this, but I want to see what you you looked for and tried and may have failed. – Funk Forty Niner Jun 05 '16 at 15:40
  • Re: Fred -ii-'s comment: It's always useful to see what people have tried as it helps to understand the level people are working at (or failing to work at... as is usually the case whenever I try anything even vaguely advanced (so many node.js knightmares -- it's a little bit like being in da 'nam)). – Peter David Carter Jun 05 '16 at 15:46
  • No need to post scripts, I want to know the process behind it more than anything. I haven't tried anything, because I don't know how to do it. Posting the question in hopes of getting some direction on where to start, ty Fred – LemonLime Jun 05 '16 at 15:48
  • if you are using php you can use filter_var for email as well with some javascript code. – Abhishek Gurjar Jun 05 '16 at 15:54

2 Answers2

1

Something like this should do the trick.

var text;
var email = document.getElementById("emailadress");
function validateMail(){
   if (email == "specificemail@gmail.com")
   text = Email correct.
}
  else{
  text = Email incorrect.  
}

document.getElementById("email").innerHTML = text;
swipeales
  • 127
  • 1
  • 2
  • 12
  • Using a JS only method will fail if someone disables JS. I personally always like to use both serverside and client-side, never only client-side. – Funk Forty Niner Jun 05 '16 at 15:49
  • thanks is this good piece of code? im learning js – swipeales Jun 05 '16 at 15:52
  • You're welcome. I'm sure it's good, I was just saying that using a JS only method will fail if JS is disabled. We'll let the OP see what they think ;-) After all, they did tag as javascript. – Funk Forty Niner Jun 05 '16 at 15:53
  • yes he should use node.js or php for server side :) – swipeales Jun 05 '16 at 15:54
  • So doing it in JS leaves it vulnerable to attacks? Is that also true for mobile app hybrids (the project i'm working on)? – LemonLime Jun 05 '16 at 15:56
  • Ty for this swipe, its super useful. I edited my question though because I think I was asking it the wrong way lol. I don't need to require any email in particular, just the school extension so non-students can't log in – LemonLime Jun 05 '16 at 15:58
-1

You can include <input name="email" type="email" required /> in <form> element. required attribute requires user input in that specific field.

guest271314
  • 1
  • 15
  • 104
  • 177
  • I don't think that that is what the question is about. Btw, not my dv. – Funk Forty Niner Jun 05 '16 at 15:38
  • @Fred-ii- _"I don't think that that is what the question is about"_ What do you believe Question is asking? – guest271314 Jun 05 '16 at 15:39
  • "downvote" description? – guest271314 Jun 05 '16 at 15:40
  • Question is not about requiring e-mail address. It's about verify & require. He doesn't need an email address. He needs "the" email address. – Ali1928 Jun 05 '16 at 15:40
  • @guest271314 Read the question again and very carefully. More specifically: *"but I don't know how to require a specific email (e.g. john@notarealcollege.edu)"* – Funk Forty Niner Jun 05 '16 at 15:41
  • @Ali _"He doesn't need an email address. He needs "the" email address."_ An email address has to be typed by user to be able to verify – guest271314 Jun 05 '16 at 15:42
  • @Fred-ii- You cannot require a specific email address. You can process and validate the email address input by user – guest271314 Jun 05 '16 at 15:43
  • @guest271314 yes it is possible. – Funk Forty Niner Jun 05 '16 at 15:44
  • @Fred-ii- How would you require a specific email address without providing that same the email address to the user? What would be purpose of an email field if the email address is pre-selected? – guest271314 Jun 05 '16 at 15:44
  • @guest271314 one would check if it contains a specific/exact string? ;-) – Funk Forty Niner Jun 05 '16 at 15:45
  • @Fred-ii- _"one would check if it contains a specific/exact string?"_ Yes, that is what `html` at post does? That is, requires an email address. Though user would need to input the value first; then check if string is valid at `php` or other server-side processing – guest271314 Jun 05 '16 at 15:46
  • I should have clarified, my wording was probably not the best. I need to require a specific address(@blank.edu) - any email with the schools extension should be able to log in – LemonLime Jun 05 '16 at 15:50
  • @Zemanor Yes, `required` attribute requires input at `` within `
    `. Check that the value is correct at `php` when `form` is submitted.
    – guest271314 Jun 05 '16 at 15:52