I’m writing an application in Android that will allow a user to register for an account only if they have a specific .edu email (abc.edu for example). I started to write some code that will verify this, but now I am wondering if there are any methods that would make this easier. I’ve only taken beginner Java/Programming courses, so I am not sure if what I’m doing is completely wrong way of going about this.
Here is my pseudo code:
Get length of inputted email.
if (
email.charat(length)-1 = u &&
email.charat(length)-2 = d &&
email.charat(length)-3 = e &&
email.charat(length)-4 = . &&
email.charat(length)-5 = c &&
email.charat(length)-6 = b &&
email.charat(length)-7 = a )
Success
else
Not a valid email
The Java String class has an
endsWithmethod you could be using:If you have an Editable, you could:
If you want that case-insensitively, just do: