You could do this in either the front end or backend
Frontend implementation with Javascript.
<input id="email" type="text"> <br>
<input id="domain_id" type="text" onblur="checkDomain()">
<button type="button">Submit</button>
<script>
function checkDomain() {
var domain = document.getElementById("email").value.split("@")[1];
var domain2 = document.getElementById("domain_id").value;
if (domain != domain2){
alert("Domains don't match");
}
}
</script>
Backend implementation in Django (assumes use of Django Forms)
You would put this in your forms.py within your form.
def clean_domain(self):
email = self.cleaned_data.get('email')
domain= self.cleaned_data.get('domain')
email_domain = #some method to get the domain of the email
if email_domain != domain:
raise forms.ValidationError(u'The domain must match the domain in your email')
return domain