Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Prashant on January 04, 2014, 12:23:34 AM

Title: Email Validation in Input template
Post by: Prashant 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 ?
Title: Re: Email Validation in Input template
Post by: Darkmax 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#.