Validate Spanish NIFS
Input is not uppercased, or stripped of any incorrect characters
199608
public static function isValid(string $nif): bool
    {
        return self::isValidDni($nif) || self::isValidNie($nif) || self::isValidCif($nif) || self::isValidOtherPersonalNif($nif);
    }
1006026
protected function validate()
    {
        // Special case:
        if ($this->n === '+0' || $this->n === '-0') {
            $this->n = '0';
        }
        if ($this->n === '0' && $this->unit === false) {
            return true;
        }
        if (!ctype_lower($this->unit)) {
            $this->unit = strtolower($this->unit);
        }
        if (!isset(HTMLPurifier_Length::$allowedUnits[$this->unit])) {
            return false;
        }
        // Hack:
        $def = new HTMLPurifier_AttrDef_CSS_Number();
        $result = $def->validate($this->n, false, false);
        if ($result === false) {
            return false;
        }
        $this->n = $result;
        return true;
    }
578698
def _remove_invalid_char(s):
    """"""

    s = ''.join([i if ord(i) >= 32 and ord(i) < 127 else '' for i in s])
    s = s.translate(dict.fromkeys(map(ord, "_%~#\\{}\":")))
    return s
852344
public function validate($input): bool
    {
        if (\is_string($input)) {
            $input = trim($input);
        }

        return (false !== $input) && (null !== $input) && ('' !== $input);
    }
294031
private function checkDisableInput()
    {
        
        $this->checkAuthInput();
        $defaults = array('language' => null);
        $this->options = array_merge($defaults, $this->options);
        if ($this->options['language'] == null){
            $this->err("Please provide the 'language' parameter.", true);
        }
        
    }
1188422
protected function validateNameRename()
    {
        $files = $this->getSubmitted('files');

        /* @var $file \SplFileInfo */
        $file = reset($files);
        $name = $this->getSubmitted('name');

        if (strlen($name) == 0) {
            $this->setErrorRequired('name', $this->translation->text('Name'));
            return false;
        }

        $pattern = $file->isFile() ? '/^[\w-.]+$/' : '/^[\w-]+$/';

        if (preg_match($pattern, $name) !== 1) {
            $this->setErrorInvalid('name', $this->translation->text('Name'));
            return false;
        }

        return true;
    }
685392
function it_matches_identifiers()
    {
        $this->match('123')->shouldReturn('123');
        $this->match('3.14')->shouldReturn('3.14');
        $this->match('-123')->shouldReturn('-123');
    }
686390
function validateName(var_name) {
        var o = "";
        for (var i = 0; i < var_name.length; i++) {
            var code = var_name.charCodeAt(i);
            if ((code > 47 && code < 58) || // numeric (0-9)
                (code > 64 && code < 91) || // upper alpha (A-Z)
                (code > 96 && code < 123) || // lower alpha (a-z)
                var_name[i] === "$" ||
                var_name[i] === "_" ||
                var_name[i] === "." ||
                var_name[i] === "&" ||
                code > 255 // utf
                ) {
                o += var_name[i];
            } else {
                o += "_$" + code + "_";
            }
        }
        if (!isNaN(o[0])) o =  "_" + o ; // first letter is number, add _ ahead.
        return o;
    }
508233
function utf8CheckIncomplete(self, buf, i) {
  var j = buf.length - 1;
  if (j < i) return 0;
  var nb = utf8CheckByte(buf[j]);
  if (nb >= 0) {
    if (nb > 0) self.lastNeed = nb - 1;
    return nb;
  }
  if (--j < i) return 0;
  nb = utf8CheckByte(buf[j]);
  if (nb >= 0) {
    if (nb > 0) self.lastNeed = nb - 2;
    return nb;
  }
  if (--j < i) return 0;
  nb = utf8CheckByte(buf[j]);
  if (nb >= 0) {
    if (nb > 0) {
      if (nb === 2) nb = 0;else self.lastNeed = nb - 3;
    }
    return nb;
  }
  return 0;
}
1296957
private function checkCreateInput()
    {
        
        $defaults = array('language' => null,
                          'languageLabel' => null,
        				  'extension' => null,
        				  'input' => dirname(__FILE__) . '/../../' . $this->options['extension'] . '/' . self::DEF_INPUT_DIR,
        				  'output' => dirname(__FILE__) . '/../../' . $this->options['extension'] . '/' . self::DEF_OUTPUT_DIR,
        				  'build' => true, // Build translation files by having a look in source code, models.
        				  'force' => false); // Do not force rebuild if locale already exist.
        
        $this->options = array_merge($defaults, $this->options);
    	
    	if (is_null($this->options['language'])) {
        	$this->err("Please provide a 'language' identifier such as en-US, fr-CA, IT, ...", true);
        } else {
        	if (is_null($this->options['extension'])) {
        		$this->err("Please provide an 'extension' for which the 'language' will be created", true);
        	} else {
        		// Check if the extension(s) exists.
        		$extensionsToCreate = explode(',', $this->options['extension']);
        		$extensionsToCreate = array_unique($extensionsToCreate);
        		foreach ($extensionsToCreate as $etc){
        			$this->options['input'] = dirname(__FILE__) . '/../../' . $etc . '/' . self::DEF_INPUT_DIR;
        			$this->options['output'] = dirname(__FILE__) . '/../../' . $etc . '/' . self::DEF_OUTPUT_DIR;
        			$extensionDir = dirname(__FILE__) . '/../../' . $etc;
        			if (!is_dir($extensionDir)) {
        				$this->err("The extension '" . $etc . "' does not exist.", true);
        			} else if (!is_readable($extensionDir)) {
        				$this->err("The '" . $etc . "' directory is not readable. Please check permissions on this directory.", true);
        			} else if (!is_writable($extensionDir)) {
        				$this->err("The '" . $etc . "' directory is not writable. Please check permissions on this directory.", true);
        			}
        			
        			// The input 'parameter' is optional.
        			// (and only used if the 'build' parameter is set to true)
					$this->checkInputOption();

					// The 'output' parameter is optional.
					$this->checkOutputOption();
				}
        	}
        }
        
    }
340353
public function transliterate()
  {
    $utf8_accents = array(
      "à" => "a",
      "ô" => "o",
      "ď" => "d",
      "ḟ" => "f",
      "ë" => "e",
      "š" => "s",
      "ơ" => "o",
      "ß" => "ss",
      "ă" => "a",
      "ř" => "r",
      "ț" => "t",
      "ň" => "n",
      "ā" => "a",
      "ķ" => "k",
      "ŝ" => "s",
      "ỳ" => "y",
      "ņ" => "n",
      "ĺ" => "l",
      "ħ" => "h",
      "ṗ" => "p",
      "ó" => "o",
      "ú" => "u",
      "ě" => "e",
      "é" => "e",
      "ç" => "c",
      "ẁ" => "w",
      "ċ" => "c",
      "õ" => "o",
      "ṡ" => "s",
      "ø" => "o",
      "ģ" => "g",
      "ŧ" => "t",
      "ș" => "s",
      "ė" => "e",
      "ĉ" => "c",
      "ś" => "s",
      "î" => "i",
      "ű" => "u",
      "ć" => "c",
      "ę" => "e",
      "ŵ" => "w",
      "ṫ" => "t",
      "ū" => "u",
      "č" => "c",
      "ö" => "oe",
      "è" => "e",
      "ŷ" => "y",
      "ą" => "a",
      "ł" => "l",
      "ų" => "u",
      "ů" => "u",
      "ş" => "s",
      "ğ" => "g",
      "ļ" => "l",
      "ƒ" => "f",
      "ž" => "z",
      "ẃ" => "w",
      "ḃ" => "b",
      "å" => "a",
      "ì" => "i",
      "ï" => "i",
      "ḋ" => "d",
      "ť" => "t",
      "ŗ" => "r",
      "ä" => "ae",
      "í" => "i",
      "ŕ" => "r",
      "ê" => "e",
      "ü" => "ue",
      "ò" => "o",
      "ē" => "e",
      "ñ" => "n",
      "ń" => "n",
      "ĥ" => "h",
      "ĝ" => "g",
      "đ" => "d",
      "ĵ" => "j",
      "ÿ" => "y",
      "ũ" => "u",
      "ŭ" => "u",
      "ư" => "u",
      "ţ" => "t",
      "ý" => "y",
      "ő" => "o",
      "â" => "a",
      "ľ" => "l",
      "ẅ" => "w",
      "ż" => "z",
      "ī" => "i",
      "ã" => "a",
      "ġ" => "g",
      "ṁ" => "m",
      "ō" => "o",
      "ĩ" => "i",
      "ù" => "u",
      "į" => "i",
      "ź" => "z",
      "á" => "a",
      "û" => "u",
      "þ" => "th",
      "ð" => "dh",
      "æ" => "ae",
      "µ" => "u",
      "ĕ" => "e",
      "œ" => "oe",
      "À" => "A",
      "Ô" => "O",
      "Ď" => "D",
      "Ḟ" => "F",
      "Ë" => "E",
      "Š" => "S",
      "Ơ" => "O",
      "Ă" => "A",
      "Ř" => "R",
      "Ț" => "T",
      "Ň" => "N",
      "Ā" => "A",
      "Ķ" => "K",
      "Ŝ" => "S",
      "Ỳ" => "Y",
      "Ņ" => "N",
      "Ĺ" => "L",
      "Ħ" => "H",
      "Ṗ" => "P",
      "Ó" => "O",
      "Ú" => "U",
      "Ě" => "E",
      "É" => "E",
      "Ç" => "C",
      "Ẁ" => "W",
      "Ċ" => "C",
      "Õ" => "O",
      "Ṡ" => "S",
      "Ø" => "O",
      "Ģ" => "G",
      "Ŧ" => "T",
      "Ș" => "S",
      "Ė" => "E",
      "Ĉ" => "C",
      "Ś" => "S",
      "Î" => "I",
      "Ű" => "U",
      "Ć" => "C",
      "Ę" => "E",
      "Ŵ" => "W",
      "Ṫ" => "T",
      "Ū" => "U",
      "Č" => "C",
      "Ö" => "Oe",
      "È" => "E",
      "Ŷ" => "Y",
      "Ą" => "A",
      "Ł" => "L",
      "Ų" => "U",
      "Ů" => "U",
      "Ş" => "S",
      "Ğ" => "G",
      "Ļ" => "L",
      "Ƒ" => "F",
      "Ž" => "Z",
      "Ẃ" => "W",
      "Ḃ" => "B",
      "Å" => "A",
      "Ì" => "I",
      "Ï" => "I",
      "Ḋ" => "D",
      "Ť" => "T",
      "Ŗ" => "R",
      "Ä" => "Ae",
      "Í" => "I",
      "Ŕ" => "R",
      "Ê" => "E",
      "Ü" => "Ue",
      "Ò" => "O",
      "Ē" => "E",
      "Ñ" => "N",
      "Ń" => "N",
      "Ĥ" => "H",
      "Ĝ" => "G",
      "Đ" => "D",
      "Ĵ" => "J",
      "Ÿ" => "Y",
      "Ũ" => "U",
      "Ŭ" => "U",
      "Ư" => "U",
      "Ţ" => "T",
      "Ý" => "Y",
      "Ő" => "O",
      "Â" => "A",
      "Ľ" => "L",
      "Ẅ" => "W",
      "Ż" => "Z",
      "Ī" => "I",
      "Ã" => "A",
      "Ġ" => "G",
      "Ṁ" => "M",
      "Ō" => "O",
      "Ĩ" => "I",
      "Ù" => "U",
      "Į" => "I",
      "Ź" => "Z",
      "Á" => "A",
      "Û" => "U",
      "Þ" => "Th",
      "Ð" => "Dh",
      "Æ" => "Ae",
      "Ĕ" => "E",
      "Œ" => "Oe",
    );

    return new self($this->toUtf8()->replace(array_keys($utf8_accents), array_values($utf8_accents)));
  }
926511
private function checkCompileInput()
    {
        
        $defaults = array('extension' => null,
                          'language' => null,
                          'input' => dirname(__FILE__) . '/../../' . $this->options['extension'] . '/' . self::DEF_INPUT_DIR,
                          'output' => dirname(__FILE__) . '/../../' . $this->options['extension'] . '/' . self::DEF_OUTPUT_DIR);
                          
        $this->options = array_merge($defaults, $this->options);
        
        if ($this->options['extension'] == null){
            $this->err("Please provide the 'extension' parameter.", true);
        }
        else if ($this->options['language'] == null){
            $this->err("Please provide the 'language' parameter.", true);
        }
        
    }
573216
def nf_input_to_cl(inp):
    
    sep = " " if inp.get("separate") else ""
    val = "'%s'" % inp.get("default") if inp.get("default") else "$%s" % inp["name"]
    return "%s%s%s" % (inp["prefix"], sep, val)
135716
function validate($value, $key, $fields, $options, $exists, \CharlotteDunois\Validation\Validator $validator) {
        $finfo = \finfo_open(\FILEINFO_MIME);
        
        if(isset($_FILES[$key])) {
            if(!\file_exists($_FILES[$key]['tmp_name'])) {
                return 'formvalidator_make_invalid_file';
            }
            
            $mime = \finfo_file($finfo, $_FILES[$key]['tmp_name']);
        } else {
            if(!$exists) {
                return false;
            }
            
            $mime = \finfo_buffer($finfo, $value);
        }
        
        \finfo_close($finfo);
        
        if(!$mime) {
            return 'formvalidator_make_invalid_file'; // @codeCoverageIgnore
        }
        
        $mime = \explode(';', $mime);
        $mime = \array_shift($mime);
        
        $val = \explode(',', $options);
        $result = \explode('/', $mime);
        
        foreach($val as $mimet) {
            $mimee = \explode('/', $mimet);
            if(\count($mimee) == 2 && \count($result) == 2) {
                if(($mimee[0] == "*" || $mimee[0] == $result[0]) && ($mimee[1] == "*" || $mimee[1] == $result[1])) {
                    return true;
                }
            }
        }
        
        return 'formvalidator_make_invalid_file';
    }
1167902
protected function validate() {
        $c = strlen($this->text);
        if ($c === 0) {
            throw new CINParseException('codabar', 'No data has been entered.');
        }

        // Checking if all chars are allowed
        for ($i = 0; $i < $c; $i++) {
            if (array_search($this->text[$i], $this->keys) === false) {
                throw new CINParseException('codabar', 'The character \'' . $this->text[$i] . '\' is not allowed.');
            }
        }

        // Must start by A, B, C or D
        if ($c == 0 || ($this->text[0] !== 'A' && $this->text[0] !== 'B' && $this->text[0] !== 'C' && $this->text[0] !== 'D')) {
            throw new CINParseException('codabar', 'The text must start by the character A, B, C, or D.');
        }

        // Must end by A, B, C or D
        $c2 = $c - 1;
        if ($c2 === 0 || ($this->text[$c2] !== 'A' && $this->text[$c2] !== 'B' && $this->text[$c2] !== 'C' && $this->text[$c2] !== 'D')) {
            throw new CINParseException('codabar', 'The text must end by the character A, B, C, or D.');
        }

        parent::validate();
    }
829241
public function validateIndexName()
    {
        if (strpos($this->indexName, '*') !== false && substr_compare($this->indexName, '*', -1, 1)) {
            $this->addError('indexName', 'Asterisk is only allowed as the last character.');

            return;
        }
        $tables = $this->getIndexNames();
        if (empty($tables)) {
            $this->addError('indexName', "Table '{$this->indexName}' does not exist.");
        } else {
            foreach ($tables as $table) {
                $class = $this->generateClassName($table);
                if ($this->isReservedKeyword($class)) {
                    $this->addError('indexName', "Table '$table' will generate a class which is a reserved PHP keyword.");
                    break;
                }
            }
        }
    }
255755
protected function _validateInput()
    {
        $result = true;

        $oxid = $this->getEditObjectId();
        $parameters = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("editval");

        // if creating new language, checking if language already exists with
        // entered language abbreviation
        if (($oxid == -1) && $this->_checkLangExists($parameters['abbr'])) {
            $this->addDisplayException('LANGUAGE_ALREADYEXISTS_ERROR');
            $result = false;
        }

        // As the abbreviation is used in database view creation, check for allowed characters
        if (!$this->checkAbbreviationAllowedCharacters($parameters['abbr'])) {
            $this->addDisplayException('LANGUAGE_ABBREVIATION_INVALID_ERROR');
            $result = false;
        }

        // checking if language name is not empty
        if (empty($parameters['desc'])) {
            $this->addDisplayException('LANGUAGE_EMPTYLANGUAGENAME_ERROR');
            $result = false;
        }

        return $result;
    }