Email Textbox Validation [SOLVED]

0 favourites
From the Asset Store
Forget about default textbox restrictions, you can create sprites atop of the textbox
  • Hi Guys,

    Once a person has entered his/her email address in a textbox, how do I validate that it's in a proper email format, e.g. eyetqg@eye.com?

    The manual says that I can set the textbox type to 'email':

    scirra.com/manual/117/textbox

    But how do I validate it, and if it's non-email format, then how do I return an error?

    EDIT June 4, 2012 - I've figured it out.

    You can use the system expression - tokencount.

    From the manual:

    "tokencount(src, separator)

    Count how many tokens occur in src using separator. For example, tokencount("apples|oranges|bananas", "|") returns 3."

    I did tokencount("bob@bob.com", "@") to check for the number of 's (there should only be one).

    Then did the same for "."'s.

    Regular expressions would have been better, but this kind of works.

  • can you upload any sample capx file for validation email?

  • Thanks for the tip about tokencount('string','token'). One oddity I've noticed is that for some reason I'm having to set the result to -1 in order to get an accurate count. Weird, but it works.

  • Hi Everyone this method is no longer working. Can someone suggest another resolution?

    Regards,

    Jatin

  • What do you mean "no longer working"?

    Tokencount works and you can use it to validate email address format, but you need to create several conditions:

    tokencount(emailText, "@")=1

    tokencount(emailText, ".")>0

    tokencount(emailText, ",")=0

    tokencount(emailText, " ")=0

    etc.

    Those are some basic checks, if you need a more strict validation, you can create a string of all characters that are not allowed in email and do something like this:

    charList="`:;'<>,/?\"   <-- this is just an example, not the actual list of restricted characters
    For x=0 to len(charList)-1
       tokencount(emailText, mid(charList,loopindex,1))=0
    [/code:1sinvf5u]
  • jatin1726

    You can use the "System|Test regex" condition to test the text in a text input box:

    String: TextBox.Text

    Regex: "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$"

    Flags: "gi"

    This should capture pretty much all email configs. Use an "else" statement beneath this condition for your invalid email actions.

  • jatin1726

    You can use the "System|Test regex" condition to test the text in a text input box:

    String: TextBox.Text

    Regex: "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$"

    Flags: "gi"

    This should capture pretty much all email configs. Use an "else" statement beneath this condition for your invalid email actions.

    Sorry mekonbekon. I am unable to understand the solution u provided. Can you please provide a capx for the solution that will be very big help for me.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • jatin1726

    Here you go:

    https://www.dropbox.com/s/qw6a0rp9f5srf ... .capx?dl=0

    Thanks a lot mekonbekon for such a quick reply. Really grateful for support.

    But the capx I check is unable to verify correct email format. for example there can't be 2 'mnu@' symbols in email id or there will be no $ in email id. Right now in capx sent by you. I am unable to restrict any user to fill email id in correct format.

  • jatin1726 I'm not sure I understand. Do you mean that invalid email addresses with 2 "@" symbols are being marked as valid, or that emails with 2 "@" are not being allowed in the demo I supplied? Can you give me some written examples of some emails that aren't working correctly?

  • jatin1726 I'm not sure I understand. Do you mean that invalid email addresses with 2 "@" symbols are being marked as valid, or that emails with 2 "@" are not being allowed in the demo I supplied? Can you give me some written examples of some emails that aren't working correctly?

    Hi, I meant this. "Do you mean that invalid email addresses with 2 "@" symbols are being marked as valid" . This was supposed to be invalid email address and shouldn't allow further typing 'iyh@' more than once. or can I display tooltip if his typed email is not in valid format? how to cross check his typed email is correct or not?

  • jatin1726

    In the demo I supplied the following shows as valid:

    ...and these all show as invalid:

    ex@mple@gmail.com

    example@gm@il.com

    ex@mple@gm@il.com

    example@@gmail.com

    Please can you supply an email address that is working incorrectly?

  • jatin1726

    In the demo I supplied the following shows as valid:

    ...and these all show as invalid:

    ex@mple@gmail.com

    example@gm@il.com

    ex@mple@gm@il.com

    example@@gmail.com

    Hi, Can you share capx in which these formats of showing mail id is invalid. That will be helpfull.

    Please can you supply an email address that is working incorrectly?

  • The capx I shared above demonstrates this as described. Here's the link again:

    https://www.dropbox.com/s/qw6a0rp9f5srf ... .capx?dl=0

    Type the email address into the text box, press enter. The text above the text box will change depending upon whether the email is valid or not.

  • The capx I shared above demonstrates this as described. Here's the link again:

    https://www.dropbox.com/s/qw6a0rp9f5srf ... .capx?dl=0

    Type the email address into the text box, press enter. The text above the text box will change depending upon whether the email is valid or not.

    Thanks a lot again. It is working perfectly fine. I have a small query. How it is identifying for invalid format when I am typing 'xtd@' symbol twice in email?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)