Text field rules
The rules a text field in your app can check, with the keyboard each one opens, and how PadCode's own fields check names, numbers and addresses, and how long each can be.
Text can be checked in two places: in the text fields of the app you build, so the people using it know when they've typed something that doesn't fit, and in PadCode's own fields, so a name, a number or an address you type is right before your app runs.
#Check what people type in your app
A Text Field or a Password Field can say what its text must look like: an email, a phone number, a number, a web address, or a pattern of your own. The field opens the keyboard for it, and when what's typed doesn't fit, your app says why, in red, under the field.
- Select the Text Field or Password Field.
- In the Inspector's Style tab, find the Validation section.
- Pick a rule in Must be.
- Optional: type your own Message. Empty uses the one in the table below.
To stop checking, set Must be back to Anything.
| Must be | What it accepts | Keyboard it opens | What it says when the text doesn't fit |
|---|---|---|---|
| Anything | Any text. Nothing is checked. | The field's usual keyboard | |
| An email address, like name@example.com. | The email keyboard, with @ and . | Use an email address, like name@example.com. | |
| Phone number | Digits, spaces, + ( ) and -, at least five of them, like +1 (555) 010-2030. | The phone keypad | Use a phone number: digits, spaces, + ( ) and -. |
| Number | A number, like 12, -4 or 3.5. A comma works for the decimal point too, like 3,5. | The number keys, with a decimal point | Use a number, like 12 or 3.5. |
| Whole number | A number without a decimal point, like 12 or -4. | The number keys | Use a whole number, like 12. |
| Web address | An address that starts with https://, like https://apple.com. | The web address keyboard | Use a web address that starts with https://. |
| Custom pattern | Text that matches your Pattern, from start to end. | The usual keyboard | That doesn't match the pattern. |
The email, phone and web address keyboards also offer the iPad's autofill for them. Every rule except Custom pattern turns autocorrect and automatic capitals off, so the iPad doesn't change what people type.
#Custom pattern
Pattern is a regular expression the whole text must match. For example, [A-Z]{2}[0-9]{4} accepts two capital letters and four digits, like AB1234.
If PadCode can't read the pattern, it says so under it: "That pattern isn't a regular expression. Check its brackets and backslashes." It's also an error in Issues, so your app won't preview until it's fixed.
#Good to know
- An empty field is fine. The message only shows once something is typed. Validation doesn't make a field required.
- Spaces at the start or end don't count, except with Custom pattern, which checks the text exactly as typed.
- It doesn't stop anything. What's typed still goes into the field's variable, and your steps still run. If a step needs the text to be right, check it first with an If: for example,
number(age) != nullis true only when age holds a number. - Your own keyboard wins. If the field itself has a Keyboard Type modifier, it keeps that keyboard instead of the rule's.
- The message is your app's. It uses your app's look: small red text under the field. A Message can be up to 200 characters.
#How PadCode's own fields check what you type
Many of PadCode's fields know what they want. They open the right keyboard, and when what you type doesn't fit, the field gets a red edge and says why under it. An empty field always passes: whether a setting is needed is checked in Issues.
| The field wants | Where | What it says |
|---|---|---|
| A name formulas can use | Variable names, secret names, color names in Assets, and the field names in Call API's Body | Start with a letter, then use letters, numbers or _, like totalCost. |
| A number | The Inspector's number boxes, like sizes and padding, and number settings in steps | Use a number, like 12 or 3.5. |
| A whole number | Max lines, Pick Photos' Limit, and Whole Number variables | Use a whole number, like 12. |
| A web address (https://) | Call API's Url, a Web Image's or Web Page's Url, a Video Player's Player, and Web Address variables | Use a web address that starts with https://. |
| A link | Open Link's Url, and a Web Link's Destination | Use a web address (https://), or a mailto: or tel: link. |
| An email address | Write Email's To | Use an email address, like name@example.com. |
| A language code | Speak Text's Language | Use a language code, like en or en-US. |
| A file name | Save File's Name | Leave out / \ : * ? " < > and |. |
Only text you type is checked here. A setting you link to a variable or a formula with ⚡︎ is checked when your app runs.
#Names
Formulas read your variables, colors and fields by name, so a name has to start with a letter (or _), then use only letters, numbers and _. totalCost and user_name work; total cost, 2nd and first-name don't.
- Variables. When you leave the name field, PadCode keeps only the characters a name can have, so
first namebecomesfirstname. A name that ends up empty, or that another variable already has, goes back to what it was. Renaming a variable renames it everywhere your app uses it. - Colors in Assets. A name that doesn't fit isn't used: the old name comes back.
- Secrets. Save to Keychain stays grayed out until the secret has a name and a value.
#How long each field can be
Every field in PadCode has a most it takes, so a name fits the row, card or tab that shows it, and nothing pasted in slows the editor down. Typing stops at the limit, and pasted text is cut to fit.
| Kind of field | Up to | For example |
|---|---|---|
| Names | 40 characters | An app's name, a screen's title, a view's name in Layers, a saved component's name, a variable, a reusable action, an image or color in Assets, a secret's name |
| Descriptions | 200 characters | An app's description, what a saved component is for, a permission's reason, a text field's Validation Message |
| Searches | 100 characters | The search fields in the Library, Add Action, Add Modifier, Choose an Icon and the typeface picker, and a Map's Place |
| Numbers | 20 characters | The Inspector's number boxes |
| Text | 2,000 characters | Everything else your app shows or sends: a title, a starting value, a step's text or address, a formula |
| Secrets and AI messages | 4,000 characters | A secret's value (API keys and tokens can be long), and a message to the AI Agent |
An app's name and description also can't be blank: Create, Add to My Apps and Save stay grayed out until both are filled in.