Fix the sign-up field check for global users
Your task
An AI added validation to your global product's sign-up form. Its rules rejected names with anything but letters, demanded a US phone format and used a strict email pattern. The tests passed, because they used the team's own names. Your team is replacing it with a validator that checks only what it must, so nobody is turned away for having a real name or a foreign number.
An assistant wrote check_registration_field(field_kind, value). It is in the editor. It has a bug. Find it and fix it.
Input and output:
field_kind:"name","email"or"phone". Any other value is unknown.value: what the person typed.- Return one status:
"ok","empty","invalid_email","too_few_digits"or"unknown_field".
Rules the tests check, in order:
- An unknown
field_kindreturns"unknown_field", whatever the value. - Trim spaces and tabs, and only those two characters, from both ends of the value. If nothing is left, return
"empty". - A name is
"ok"whenever it is not empty. Any character is allowed: hyphens, apostrophes, digits, accents and any script, in one part or many. - An email is
"invalid_email"if it contains a space character (a tab inside does not count), does not have exactly one@, has nothing before or after the@, has no.after the@, or has a domain (the part after the@) that starts or ends with.. Otherwise it is"ok". - A phone number is
"too_few_digits"when it has fewer than 4 digits from 0 to 9, and"ok"otherwise. Formatting such as+, spaces, brackets and dashes is ignored.
Examples
check_registration_field(field_kind: str, value: str) -> strExample 1
Input
check_registration_field("name", "O'Brien")Output
"ok"Example 2
Input
check_registration_field("email", "ada+news@example.co.uk")Output
"ok"Example 3
Input
check_registration_field("phone", "+91 98765 43210")Output
"ok"