Author Topic: Email Validation in Input template  (Read 4771 times)

Prashant

  • Guest
Email Validation in Input template
« on: January 04, 2014, 12:23:34 AM »
Hello! I've made a form using the input template one of which asks the user for registering their email Id. Is it possible to check from the label if the entered email id is valid ?

Darkmax

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 1
  • Posts: 93
    • View Profile
Re: Email Validation in Input template
« Reply #1 on: January 04, 2014, 01:29:49 AM »
this is not a ngui question, this is more a c# programming question.

This can be accomplished with regular expressions.

something like this:

  1. string pattern = @"^(?!\.)(""([^""\r\\]|\\[""\r\\])*""|"
  2.     + @"([-a-z0-9!#$%&'*+/=?^_`{|}~]|(?<!\.)\.)*)(?<!\.)"
  3.     + @"@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z][a-z\.]*[a-z]$";
  4.  
  5.   Regex regex = new Regex(pattern);
  6. string email = input.value;
  7. Match match = regex.Match(email);
  8. if (match.Success)
  9.     Debug.Log(email + " is correct");
  10. else
  11.     Debug.Log(email + " is incorrect");
  12.  

I didn't test this, but if doesn't work try to check how to use regular expressions on c#.