I am using html input control to feed in email address. Also, I am using required attribute but I want the input should only be from gmail.com i.e. john@gmail.com, aamir@gmail.com etc and not any other domain.
JavaScript
x
2
1
<input type="text" name="email" pattern="^[a-zA-Z0-9]+@domain.[a-zA-z]+$" required>
2
But this accept every domain and not only gmail.com.
NOTE: I need to do it with regex in html5 control not with javascript etc
Update: I am using razor syntax with asp.net mvc.
Advertisement
Answer
You can use this regex
JavaScript
1
2
1
^[a-zA-Z0-9]+@gmail.com$
2
JavaScript
1
4
1
<form>
2
<input type="text" name="email" pattern="^[a-zA-Z0-9]+@gmail.com$" required></input>
3
<input type='submit' placeholder='submit'/>
4
</form>