Suppose I have two input text fields: one for a regular phone number and another for a cellphone number. How would I go about validating that at least one field is not empty?
Eg if telephone is not empty but cellphone is empty, it's considered valid. if cellphone is not empty but telephone is empty, it's considered valid. if both telephone and cellphone are empty, it's considered invalid.
Is it possible for this to be expressed with FormEncode?
To validate with formencode that at least one field is filled.
class RequireNumber(formencode.Schema):
phone_number = formencode.validators.PhoneNumber(if_missing=None)
cell_number = formencode.validators.PhoneNumber(if_missing=None)
chained_validators = [formencode.validators.RequireIfMissing('phone_number', missing='cell_number')]
chained_validators = [formencode.validators.RequireIfMissing('cell_number', missing='phone_number')]
use document.GetElementByID to get the value in the input text
if reqularPhoneNumber != "" or cellPhoneNumber != "":
# Do your stuff
or
- is the logical or operator, the if
is evaluated as true if either of the conditions is true
EDIT: Changed || to or as with Python
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.