On this page
code
ការ Validate ចម្លើយ
វិធីមួយ ដើម្បី ធានា data quality គឺ ការ បន្ថែម constraints ទៅ data fields ក្នុង form ។ Constraints ជួយ ការ ពារ users ពី ការ ដាក់ ចម្លើយ invalid ។
- បន្ថែម column ថ្មី ហៅ “constraint” ទៅ form ។
- ក្នុង column “constraint”, ដាក់ formula ដែល បញ្ជាក់ ដែន កំណត់ ។
ឧទាហរណ៍
name | constraint |
|---|---|
| Income | . >= 0 & . <= 1000000 |
Hard constraint
hard constraint block form submission ទាំង ស្រុង ប្រ សិ ន បើ value ដែល បញ្ចូល មិន satisfy expression ។
type | name | label | constraint | constraint_message |
|---|---|---|---|---|
| integer | age | Age of respondent | . > 0 and . <= 120 | Age must be between 1 and 120 |
| decimal | temperature | Body temperature (°C) | . >= 35 and . <= 42 | Temperature must be between 35°C and 42°C |
| text | phone | Phone number | regex(., '^[0-9]{10}$') | Enter a 10-digit phone number |
Multiple conditions
. >= 0 and . <= 100
ការ ប្រើ regex() សម្រាប់ pattern validation
type | name | label | constraint | constraint_message |
|---|---|---|---|---|
| text | Email address | regex(., '^[^@]+@[^@]+\.[^@]+$') | Enter a valid email address |
ការ reference fields ផ្សេង ក្នុង constraint
type | name | label | constraint | constraint_message |
|---|---|---|---|---|
| integer | end_year | End year | . >= ${start_year} | End year must be after start year |
Soft alert
soft alert ព្រមានដ ល់ enumerator ថា value មើល ទៅ unusual ប៉ុន្ដែ អនុញ្ញាតឱ្យ proceed ។
type | name | label | relevant |
|---|---|---|---|
| integer | children | Number of children | |
| note | children_warning | Warning: You entered ${children} children. Please confirm this is correct. | . > 15 |
| trigger | children_confirm | Confirm the number of children is correct | ${children} > 15 |
ប្រើ hard constraints សម្រាប់ values ដែល impossible ។ ប្រើ soft alerts សម្រាប់ values ដែល unlikely ប៉ុន្ដែ possible ។
តើទំព័រនេះមានប្រយោជន៍ទេ?