Email Textbox Validation [SOLVED]

Get help using Construct 2

Post » Sat Jun 02, 2012 11:23 am

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. [email protected]?

The manual says that I can set the textbox type to 'email':
http://www.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("[email protected]", "@") 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.

EyeHawk2012-06-03 14:15:34
B
36
S
8
G
3
Posts: 328
Reputation: 7,762

Post » Tue Apr 30, 2013 7:47 am

can you upload any sample capx file for validation email?
B
7
S
2
G
3
Posts: 13
Reputation: 2,266

Post » Sat Apr 18, 2015 3:32 pm

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.
B
9
S
1
Posts: 33
Reputation: 612

Post » Wed Oct 25, 2017 4:30 am

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

Regards,
Jatin
Subway Surfer Game Template: http://bit.ly/subwaysurfertemplate
B
64
S
25
G
1
Posts: 107
Reputation: 5,972

Post » Wed Oct 25, 2017 5:24 am

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:
Code: Select all
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
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :)
B
17
S
9
G
68
Posts: 1,037
Reputation: 37,137

Post » Wed Oct 25, 2017 8:52 am

@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._%+-][email protected][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.
B
22
S
9
G
4
Posts: 476
Reputation: 4,327

Post » Fri Nov 03, 2017 4:47 am

mekonbekon wrote:@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._%+-][email protected][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.
Subway Surfer Game Template: http://bit.ly/subwaysurfertemplate
B
64
S
25
G
1
Posts: 107
Reputation: 5,972

Post » Fri Nov 03, 2017 9:16 am

B
22
S
9
G
4
Posts: 476
Reputation: 4,327

Post » Fri Nov 03, 2017 10:19 am

mekonbekon wrote:@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 '@' 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.
Subway Surfer Game Template: http://bit.ly/subwaysurfertemplate
B
64
S
25
G
1
Posts: 107
Reputation: 5,972

Post » Fri Nov 03, 2017 11:04 am

@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?
B
22
S
9
G
4
Posts: 476
Reputation: 4,327

Next

Return to How do I....?

Who is online

Users browsing this forum: dop2000 and 9 guests