How do I compare specific characters in a Textbox?

Get help using Construct 2

Post » Thu Feb 05, 2015 7:17 pm

I'm creating a registration form for my game. Everything is set up and working great, users can create a username,email,password all of which is stored on my SQL database. I also have it set up so that the entered information is being checked in real time against my database to ensure no duplicate usernames or e-mails are trying to be registered. The only issue I'm having now is that people can register emails such as "A" or "asdasd" or whatever. Is there anyway to check that the text in the textbox contains a minimum of an "@" and a ".com"? So if the user enters an e-mail address that doesn't contain at least an "@" and a ".com" I can return false to disable the submit registration button?
Image
B
33
S
16
G
2
Posts: 184
Reputation: 4,034

Post » Thu Feb 05, 2015 7:59 pm

So after much searching I came upon this amazing plugin for an Advanced Textbox object. It really is extremely helpful and suggest you give it a download if your project contains textbox object. Huge thanks to Pinco for this amazing help!

Link to the plugin: plugin-advanced-textbox_t82223

Other than the normal textbox properties, this one provides also:

PROPERTIES:

- Background Color: allows you to pick a color for the background.

- Transparent Background: allows you to disable the background color and have a transparent background.

- Font: allows you to choose the font to use (like for the label).

- Font Color: allows you to specify the font color.

- Borders: allows to toggle the text box borders. If disabled it also remove the border highlight that certain browsers (like chrome) adds to the text input areas.

- Top/Bottom/Left/Right Margin: allows to specify the distance in pixel that the text should keep from the margins.

- Horizontal Alignment: allows you to customize the text alignment.

- Select all on focus: if set to yes, when the textbox get the focus will select all the text inside.


TRIGGERS:

- On Focus Gain: triggered when the textbox has the focus.

- On Focus Lost: triggered when the textbox lose the focus.


CONDITIONS:

- Has Focus: return true if the textbox has the focus.

- Validate: return true if the textbox content is valid (based on the content type selected).


ACTIONS:

- Set Web Font: like for the text object, this allows to use webfonts on the textbox object.

- Set Background Color: change the background color for the textbox object. It accepts the following color formats:
- "rgb(0,0,0)": rgb function (remember to always use the quotes)
- "#FFFFFF": hex color value (remember to always use the quotes)
- "transparent": string color name

- Toggle Borders: allows to enable/disable the textbox borders.

- Scroll Top: scroll to the top line of the textarea.

- Scroll Bottom: scroll to the bottom line of the textarea.

- Select All: select the whole content of the textbox.

- Append Text: append text at the end of the currently existing one.

- Append New Line Text: append text at the end of the currently existing one in a new line.


EXPRESSIONS:

- TextAfter: Get the text after the caret text box's text.

- TextBefore: Get the text before the caret text box's text.
Image
B
33
S
16
G
2
Posts: 184
Reputation: 4,034

Post » Thu Feb 05, 2015 9:56 pm

You could also use tokencount and put @ as separator. If tokencount is less than 1 (or even 2 in event of email) it should be invalid.

https://www.scirra.com/manual/126/system-expressions

Maybe there is some even better condition here.
B
12
S
6
G
2
Posts: 99
Reputation: 1,727


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 2 guests