Walidacja REGON dla MySQL


CREATE FUNCTION `valid_regon`(`regon` varchar(255)) RETURNS int(1)
    READS SQL DATA
BEGIN

DECLARE cs integer DEFAULT 0;
DECLARE m integer  DEFAULT 0;
DECLARE i integer DEFAULT 0;

IF (char_length(regon) = 7) THEN

       simple_loop: LOOP
         SET i=i+1;
                        if i in (1) then
                                SET m = 2;
                        elseif i in (2) then
                                SET m = 3;
                        elseif i in (3) then
                                SET m = 4;
                        elseif i in (4) then
                                SET m = 5;
                        elseif i in (5) then
                                SET m = 6;
                        elseif i in (6) then
                              ...
Zobacz więcej

Walidacja PESEL dla MySQL


CREATE FUNCTION `valid_pesel`(`pesel` varchar(255)) RETURNS int(1)
    READS SQL DATA
BEGIN

DECLARE cs integer DEFAULT 0;
DECLARE m integer  DEFAULT 0;
DECLARE i integer DEFAULT 0;

IF (char_length(pesel) = 11) THEN

       simple_loop: LOOP
         SET i=i+1;
                        if i in (1,5,9) then
                                SET m = 1;
                        elseif i in (2,6,10) then
                                SET m = 3;
                        elseif i in (3,7) then
                                SET m = 7;
                        elseif i in (4,8) then
                                SET m = 9;
                        end if;
			SET cs = cs + (m * substr(pesel,i,1));

         IF i=10 THEN
            LEAVE simple_loop;
         END IF;
 ...
Zobacz więcej

Walidacja NIP dla MySQL

CREATE FUNCTION `valid_nip`(`nip` varchar(255)) RETURNS int(1)
    READS SQL DATA
BEGIN

DECLARE cs integer DEFAULT 0;
DECLARE m integer  DEFAULT 0;
DECLARE i integer DEFAULT 0;

IF (char_length(nip) = 10) THEN

       simple_loop: LOOP
         SET i=i+1;
                        if i in (4) then
                                SET m = 2;
                        elseif i in (5) then
                                SET m = 3;
                        elseif i in (6) then
                               SET m = 4;
                        elseif i in (2,7) then
                                SET m = 5;
                        elseif i in (1,8) then
                               SET m = 6;
                        elseif i in (3,9) then
                                S...
Zobacz więcej

Walidacja PESEL dla MSSQL


CREATE FUNCTION valid_pesel( @pesel nvarchar(255) ) RETURNS INTEGER
AS
BEGIN
	DECLARE @cs int
	DECLARE @m int
	DECLARE @i int
	DECLARE @res int
	SET @pesel = cast(@pesel as nvarchar)
	SET @cs = 0
	SET @m = 0
	SET @i = 1
	IF LEN(@pesel) = 11
		begin
			WHILE (@i <= 10)
			BEGIN
                  if @i in (1,5,9) SET @m = 1
                  else if @i in (2,6,10) SET @m = 3
                  else if @i in (3,7) SET @m = 7
                  else if @i in (4,8) SET @m = 9								
				  SET @cs = @cs + (@m * SUBSTRING(@pesel,@i,1))
				  SET @i = (@i + 1)
			END 
			SET @cs = @cs % 10
            if (@cs > 0) SET @cs = 10 - @cs
			IF ( @cs = SUBSTRING(@pesel,11,1) )
				SET @res = 1
			ELSE
				SET @res = 0
		END
	ELSE
		BEGIN
			SET @res = -1
		END
	RETURN @res
END

Zobacz więcej

Walidacja REGON dla MSSQL

CREATE FUNCTION valid_regon( @regon nvarchar(255) ) RETURNS INTEGER
AS
BEGIN
	DECLARE @cs int
	DECLARE @m int
	DECLARE @i int
	DECLARE @res int
	SET @regon = cast(@regon as nvarchar)
	SET @cs = 0
	SET @m = 0
	SET @i = 1
	IF LEN(@regon) = 7
		BEGIN
			WHILE (@i <= 6)
			BEGIN
                  IF @i IN (1) SET @m = 2
                  ELSE IN @i in (2) SET @m = 3
                  ELSE IN @i in (3) SET @m = 4
                  ELSE IN @i in (4) SET @m = 5
                  ELSE IN @i in (5) SET @m = 6
                  ELSE IN @i in (6) SET @m = 7
				  SET @cs = @cs + (@m * SUBSTRING(@regon,@i,1))
				  SET @i = (@i + 1)
			END
			SET @cs = @cs % 11
			IF ( @cs = SUBSTRING(@regon,7,1) )
				SET @res = 1
			ELSE
				SET @res = 0
		END
	ELSE IF LEN(@regon) = 9
...
Zobacz więcej

Walidacja NIP dla MSSQL

CREATE FUNCTION valid_nip( @nip nvarchar(255) ) RETURNS INTEGER
AS
BEGIN
 DECLARE @cs int
 DECLARE @m int
 DECLARE @i int
 DECLARE @res int
 SET @nip = cast(@nip as nvarchar)
 SET @cs = 0
 SET @m = 0
 SET @i = 1
 IF LEN(@nip) = 10
 begin
 WHILE (@i &lt;= 9)
 BEGIN
 if @i in (4) SET @m = 2
 else if @i in (5) SET @m = 3
 else if @i in (6) SET @m = 4
 else if @i in (2,7) SET @m = 5
 else if @i in (1,8) SET @m = 6
 else if @i in (3,9) SET @m = 7
 SET @cs = @cs + (@m * SUBSTRING(@nip,@i,1))
 SET @i = (@i + 1)
 END
 SET @cs = @cs % 11
 IF ( @cs = SUBSTRING(@nip,10,1) )
 SET @res = 1
 ELSE
 SET @res = 0
 END
 ELSE
 BEGIN
 SET @res = -1
 END
 RETURN @res
END
Zobacz więcej

Walidacja NIP dla Zend Framework

Walidator nipu:
tutaj wgrywamy pliczek o nazwie Nip.php do katalogu /zend/Validate/
Kod validatora:


/**
 * @see Zend_Validate_Abstract
 */ 
require_once 'Zend/Validate/Abstract.php'; 
  
class Zend_Validate_Nip extends Zend_Validate_Abstract
{ 
    /**
     * Validation failure message key for when the value is not of valid length
     */
    const LENGTH   = 'numLength';

    /**
     * Validation failure message key for when the value fails the mod  checksum
     */
    const CHECKSUM = 'numChecksum';


     /**
     * Digits filter for input
     *
     * @var Zend_Filter_Digits
     */
    protected static $_filter = null;
 

    /**
     * @var array
     */ 
    protected $_messageTemplates = array( 
        self::LENGTH   = "'%value%' must contain 1...
Zobacz więcej

Walidacja ISBN dla Zend Framework

 
/**
 * @see Zend_Validate_Abstract
 */ 
require_once 'Zend/Validate/Abstract.php'; 

/**
 * Zend_Validate_StringLength
 */
 
require_once 'Zend/Validate/StringLength.php';

/**
 * Zend_Validate_Digits
 */
require_once 'Zend/Validate/Digits.php';

/**
 * @category   Zend
 * @package    Zend_Validate
 * @copyright  Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend...
Zobacz więcej

Walidacja REGON dla Zend Framework

/**
 * @see Zend_Validate_Abstract
 */ 
require_once 'Zend/Validate/Abstract.php'; 
 
class Zend_Validate_Regon extends Zend_Validate_Abstract
{ 
    /**
     * Validation failure message key for when the value is not of valid length
     */
    const LENGTH   = 'numLength';

    /**
     * Validation failure message key for when the value fails the mod  checksum
     */
    const CHECKSUM = 'numChecksum';


     /**
     * Digits filter for input
     *
     * @var Zend_Filter_Digits
     */
    protected static $_filter = null;
 

    /**
     * @var array
     */ 
    protected $_messageTemplates = array( 
        self::LENGTH   = "'%value%' must contain either 7, 9 or 14 digits",
        self::CHECKSUM = "Luhn algorithm (mod-11 checksum) failed on '%val...
Zobacz więcej

Walidacja PESEL dla Zend Framework

/**
 * @see Zend_Validate_Abstract
 */ 
require_once 'Zend/Validate/Abstract.php'; 
 
class Zend_Validate_Pesel extends Zend_Validate_Abstract
{ 
    /**
     * Validation failure message key for when the value is not of valid length
     */
    const LENGTH   = 'numLength';

    /**
     * Validation failure message key for when the value fails the mod  checksum
     */
    const CHECKSUM = 'numChecksum';


     /**
     * Digits filter for input
     *
     * @var Zend_Filter_Digits
     */
    protected static $_filter = null;
 

    /**
     * @var array
     */ 
    protected $_messageTemplates = array( 
        self::LENGTH   = "'%value%' must contain 11 digits",
        self::CHECKSUM = "Luhn algorithm (mod-10 checksum) failed on '%value%'"        
...
Zobacz więcej