Use a regular expression like
/.+@(gmail|yahoo)\.com$/
Depending on the used language and the type of the input box the check can be performed in a validation function.
JavaScript example:
function isGmailOrYahoo(mailaddr) {
var re = /.+@(gmail|yahoo)\.com$/;
return re.test(mailaddr);
}
[EDIT]
From comment:
i should not use regular exp
Then you can use
String.prototype.endsWith() - JavaScript | MDN[
^]:
function isGmailOrYahoo(mailaddr) {
return mailaddr.endsWith('@gmail.com') || mailaddr.endsWith('@yahoo.com');
}
[/EDIT]
[EDIT]
Further reads for ASP.NET control validations:
Types of Validation for ASP.NET Server Controls[
^]
In your case you have to use the
CustomValidator Class (System.Web.UI.WebControls)[
^] when regex is not allowed.
If you want to use client side JavaScript, see
Client-Side Validation for ASP.NET Server Controls[
^] and
Client Side Validation using JavaScript[
^].
[/EDIT]