Validates address fields
486604
protected function validateFieldsAddress()
    {
        $this->validateFieldAddress('address_1');
        $this->validateFieldAddress('address_2');
        $this->validateFieldAddress('phone');
        $this->validateFieldAddress('middle_name');
        $this->validateFieldAddress('last_name');
        $this->validateFieldAddress('first_name');
        $this->validateFieldAddress('postcode');
        $this->validateFieldAddress('company');
        $this->validateFieldAddress('fax');
    }
1171586
def _validate_address(self, address):
        
        parsed = compat.urlparse(address)
        if not parsed.path:
            raise ValueError("Invalid {} address: {}".format(
                self.__class__.__name__, parsed))
        return parsed
1302847
function validate($value, $key, $fields, $options, $exists, \CharlotteDunois\Validation\Validator $validator) {
        if(isset($_FILES[$key]) && \file_exists($_FILES[$key]['tmp_name']) && $_FILES[$key]['error'] == 0) {
            $v = \round((\filesize($_FILES[$key]['tmp_name']) / 1024));
        } else {
            if(!$exists) {
                return false;
            }
            
            if(\is_array($value)) {
                $v = \count($value);
            } elseif(\is_numeric($value)) {
                $v = $value;
            } else {
                $v = \mb_strlen($value);
            }
        }
        
        if($v < $options) {
            if(\is_string($value)) {
                return array('formvalidator_make_min_string', array('{0}' => $options));
            } else {
                return array('formvalidator_make_min', array('{0}' => $options));
            }
            
        }
        
        return true;
    }
158659
private void addAddressToList(String newAddress, boolean validateOnly) {
        int start = 0;
        char delimiter = '.';
        String sub;
        int radix = 10;

        // Address initially set to all zeroes
        int addressToAdd[] = new int[IP_ADDR_NUMBERS];
        for (int i = 0; i < IP_ADDR_NUMBERS; i++) {
            addressToAdd[i] = 0;
        }

        int slot = IP_ADDR_NUMBERS - 1;
        // assume the address is IP4, but change to IP6 if there is a colon
        if (newAddress.indexOf('.') == -1) {
            // if no ".", then assume IPv6 Address
            delimiter = ':';
            radix = 16;
        }

        String addr = newAddress;
        while (true) {
            // fill address from back to front
            start = addr.lastIndexOf(delimiter);
            if (start != -1) {
                sub = addr.substring(start + 1);

                if (sub.trim().equals("*")) {
                    addressToAdd[slot] = -1; // 0xFFFFFFFF is the wildcard.
                } else {
                    addressToAdd[slot] = Integer.parseInt(sub, radix);
                }
            } else {
                if (addr.trim().equals("*")) {
                    addressToAdd[slot] = -1; // 0xFFFFFFFF is the wildcard.
                } else {
                    addressToAdd[slot] = Integer.parseInt(addr, radix);
                }
                break;
            }
            slot = slot - 1;
            addr = addr.substring(0, start);
        }

        if (!validateOnly) {
            putInList(addressToAdd);
        }
    }
1309397
def validate_value(self, value):
        """"""
        super(ValuesListField, self).validate_value(value)

        if value is not None:
            if value not in self.selection_to_id_map:
                raise ValidationError(
                    self.record,
                    'Field "{}" invalid value "{}". Valid options: {}'.format(
                        self.name,
                        value,
                        ', '.join(self.selection_to_id_map.keys())
                    )
                )
201723
protected function validateCityAddress()
    {
        $field = 'city_id';

        if ($this->isExcluded($field) || $this->isError('country')) {
            return null;
        }

        $value = $this->getSubmitted($field);

        if ($this->isUpdating() && !isset($value)) {
            $this->unsetSubmitted($field);
            return null;
        }

        $label = $this->translation->text('City');
        $format = $this->getCountryFormatAddress();

        if (empty($value) && !empty($format['city_id']['required'])) {
            $this->setErrorRequired($field, $label);
            return false;
        }

        // City ID can be either numeric ID or non-numeric human name
        if (is_numeric($value)) {
            if ($this->city->get($value)) {
                return true;
            }
            $this->setErrorUnavailable($field, $label);
            return false;
        }

        if (empty($value)) {
            return true;
        }

        if (mb_strlen($value) > 255) {
            $this->setErrorLengthRange($field, $label);
            return false;
        }

        // Try to convert human name to a numeric ID
        $country = $this->getSubmitted('country');
        $state_id = $this->getSubmitted('state_id');

        if (empty($country) || empty($state_id)) {
            return true;
        }

        $conditions = array(
            'name' => $value,
            'country' => $country,
            'state_id' => $state_id
        );

        foreach ((array) $this->city->getList($conditions) as $city) {
            if (strcasecmp($city['name'], $value) === 0) {
                $this->setSubmitted($field, $city['city_id']);
                break;
            }
        }

        return true;
    }
1346294
def validate_business(form, field):
    
    if not is_valid_mail(field.data, multi=False) and not re.match(r'^[a-zA-Z0-9]{13}$', field.data):
        raise ValidationError(_('Invalid email address / paypal ID'))
871772
function validatefieldCodes() {
    //Flag for finding a duplicate field code
    var duplicateFieldCode = false;
    var invalidFieldCode = false;
    var fieldCodes = {};

    formData.pages = _.map(formData.pages, function(page) {
      page.fields = _.map(page.fields, function(field) {
        var fieldCode = field.fieldCode;

        //If not set, then just return the field.
        if (fieldCode === null || typeof(fieldCode) === "undefined") {
          return field;
        }

        //Checking for duplicate field code. It must be a string.
        if (typeof(fieldCode) === "string") {
          //If the length of the code is 0, then don't save it.
          if (fieldCode.length === 0) {
            delete field.fieldCode;
          } else {
            //Checking for duplicate field code
            if (fieldCodes[fieldCode]) {
              duplicateFieldCode = true;  //Flagging the field as duplicate
            } else {
              fieldCodes[fieldCode] = true;
            }
          }
        } else {
          invalidFieldCode = true; //Field codes must be a string.
        }

        return field;
      });

      return page;
    });

    if (duplicateFieldCode) {
      return new Error("Duplicate Field Codes Detected. Field Codes Must Be Unique In A Form.");
    }

    if (invalidFieldCode) {
      return new Error("Invalid Field Code. Field Codes Must Be A String.");
    }

    //All valid. can proceed to saving the form.
    return undefined;
  }
660878
protected function validateAccountFields()
    {
        $regexpEmail = '/^[^@<>,; "\']+@([^.@ ,;]+\.)+[^.@ ,;]+$/';

        if (empty($this->submittedValues[Tag::ContractCode])) {
            $this->errorMessages[Tag::ContractCode] = $this->t('message_validate_contractcode_0');
        } elseif (!is_numeric($this->submittedValues[Tag::ContractCode])) {
            $this->errorMessages[Tag::ContractCode] = $this->t('message_validate_contractcode_1');
        } else {
            // Prevent errors where a copy & paste of the contractcode from the
            // welcome mail includes spaces or tabs before or after the code.
            $this->submittedValues[Tag::ContractCode] = trim($this->submittedValues[Tag::ContractCode]);
        }

        if (empty($this->submittedValues[Tag::UserName])) {
            $this->errorMessages[Tag::UserName] = $this->t('message_validate_username_0');
        } elseif ($this->submittedValues[Tag::UserName] !== trim($this->submittedValues[Tag::UserName])) {
            $this->warningMessages[Tag::UserName] = $this->t('message_validate_username_1');
        }

        if (empty($this->submittedValues[Tag::Password])) {
            $this->errorMessages[Tag::Password] = $this->t('message_validate_password_0');
        } elseif ($this->submittedValues[Tag::Password] !== trim($this->submittedValues[Tag::Password])) {
            $this->warningMessages[Tag::Password] = $this->t('message_validate_password_1');
        } elseif (strpbrk($this->submittedValues[Tag::Password], '`\'"#%&;<>\\') !== false) {
            $this->warningMessages[Tag::Password] = $this->t('message_validate_password_2');
        }

        if (empty($this->submittedValues[Tag::EmailOnError])) {
            $this->errorMessages[Tag::EmailOnError] = $this->t('message_validate_email_1');
        } elseif (!preg_match($regexpEmail, $this->submittedValues[Tag::EmailOnError])) {
            $this->errorMessages[Tag::EmailOnError] = $this->t('message_validate_email_0');
        }
    }
1332636
public function validate(Address $address)
    {
        $this->validationContext = $this->validator->startContext();

        $this->validateField('firstname', $address->getFirstname(), [new NotBlank()]);
        $this->validateField('lastname', $address->getLastname(), [new NotBlank()]);

        if ($this->validationContext->getViolations()->count()) {
            throw new ValidationException($this->validationContext->getViolations());
        }
    }
29864
@Override
	public void validate() throws AddressStringException {
		if(isValidated()) {
			return;
		}
		synchronized(this) {
			if(isValidated()) {
				return;
			}
			//we know nothing about this address.  See what it is.
			try {
				parsedAddress = getValidator().validateAddress(this);
				isValid = true;
			} catch(AddressStringException e) {
				cachedException = e;
				isValid = false;
				throw e;
			}
		}
	}
165560
def validateaddress(self, address: str) -> bool:
        ""

        try:
            Address.from_string(address, self.network_properties)
        except InvalidAddress:
            return False

        return True
812504
def validate_each(record, attribute, value)
      unless value.blank?
        record.errors[attribute] << (options[:message] || 'is not a valid email address') unless value =~ VALID_EMAIL_REGEX
      end
    end
267732
public static boolean validateEmailAdress(final String emailAddress)
	{
		boolean isValid = true;
		try
		{
			final InternetAddress internetAddress = new InternetAddress(emailAddress);
			internetAddress.validate();
		}
		catch (final AddressException e)
		{
			isValid = false;
		}
		return isValid;
	}
437083
def validate_email(self, email_address):

        '''
            
        '''

        title = '%s.validate_email' % __class__.__name__

    # validate inputs
        object_title = '%s(email_address="")' % title
        email_address = self.fields.validate(email_address, '.email_address', object_title)

    # construct request_kwargs
        request_kwargs = {
            'url': '%s/address/validate' % self.api_endpoint,
            'params': { 'address': email_address }
        }

    # send request
        response_details = self._get_request(**request_kwargs)

        return response_details
244882
function validate($value, $key, $fields, $options, $exists, \CharlotteDunois\Validation\Validator $validator) {
        if(!$exists) {
            return false;
        }
        
        if(!\is_array($value)) {
            return 'formvalidator_make_array';
        }
        
        if(!empty($options)) {
            foreach($value as $val) {
                $type = \gettype($val);
                if($type === 'double') {
                    $type = 'float'; // @codeCoverageIgnore
                }
                
                if($type !== $options) {
                    return array('formvalidator_make_array_subtype', array('{0}' => $options));
                }
            }
        }
        
        return true;
    }
928571
protected function validateRelationFields()
    {
        if (empty($this->submittedValues['sendCustomer']) && !empty($this->submittedValues['emailAsPdf'])) {
            $this->warningMessages['conflicting_options'] = $this->t('message_validate_conflicting_options');
        }
    }