Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Split Validate_IR into its own repository.

  • Loading branch information...
commit ddb8bc521be9ac2c7d8ea9f675ced46579f0934a 1 parent b7a81f9
@gauthierm gauthierm authored
View
153 Validate/IR.php
@@ -1,153 +0,0 @@
-<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
-
-/**
- * Specific validation methods for data used in the Iran.
- *
- * PHP version 5
- *
- * This source file is subject to the New BSD license,
- * That is bundled with this package in the file LICENSE,
- * and is available through the world-wide-web at http://www.opensource.org/licenses/bsd-license.php
- * If you did not receive a copy of the new BSDlicense and are unable to obtain it through the world-wide-web,
- * please send a note to pajoye@php.net so we can mail you a copy immediately.
- *
- * @category Validate
- * @package Validate_IR
- * @author Arash Hemmat <arash.hemmat@gmail.com>
- * @copyright 2011 Arash Hemmat
- * @license http://www.opensource.org/licenses/bsd-license.php new BSD
- * @link http://pear.php.net/package/Validate_IR
- */
-class Validate_IR
-{
- /**
- * Check for Persian/Farsi characters and number an zero width non-joiner space.
- * Also accpets latin numbers preventing potential problem until PHP becomes fully unicode compatible.
- *
- * @param string $check The value to check.
- *
- * @return boolean
- * @access public
- */
- function alphaNumeric($check)
- {
- $pattern = '/[^\x{0600}-\x{06FF}\x{FB50}-\x{FDFD}\x{FE70}-\x{FEFF}\x{0750}-\x{077F}0-9\s\x{200C}]+/u';
- return !preg_match($pattern, $check);
- }
-
- /**
- * Checks for Persian/Farsi digits only and won't accept Arabic and Latin digits.
- *
- * @param string $check The value to check.
- *
- * @return boolean
- * @access public
- */
- function numeric($check)
- {
- $pattern = '/[^\x{06F0}-\x{06F9}\x]+/u';
- return !preg_match($pattern, $check);
- }
-
- /**
- * Validation of Iran credit card numbers.
- *
- * @param string $check The value to check.
- *
- * @return boolean
- * @access public
- */
- function creditCard($check)
- {
- $pattern = '/^[0-9]{4}-?[0-9]{4}-?[0-9]{4}-?[0-9]{4}$/';
- return preg_match($pattern, $check);
- }
-
- /**
- * Checks phone numbers for Iran
- *
- * @param string $check The value to check.
- *
- * @return boolean
- * @access public
- */
- function phoneNumber($check)
- {
- $pattern = '/^[- .\(\)]?((98)|(\+98)|(0098)|0){1}[- .\(\)]{0,3}[1-9]{1}[0-9]{1,}[- .\(\)]*[0-9]{3,8}[- .\(\)]?$/';
- return preg_match($pattern, $check);
- }
-
- /**
- * Checks mobile numbers for Iran
- *
- * @param string $check The value to check.
- *
- * @return boolean
- * @access public 0 9 124061351
- */
- function mobileNumber($check)
- {
- $pattern = '/^[- .\(\)]?((98)|(\+98)|(0098)|0){1}[- .\(\)]{0,3}((91)|(93)){1}[0-9]{8}$/';
- return preg_match($pattern, $check);
- }
-
- /**
- * Checks postal codes for Iran
- *
- * @param string $check The value to check.
- *
- * @return boolean
- * @access public
- */
- function postalCode($check)
- {
- $pattern = '/^\d{10}$/';
- return preg_match($pattern, $check);
- }
-
- /**
- * Checks social security numbers for Iran called "kode melli".
- * kode melli's last digit from left is the check digit, here is the algorithm:
- * A= last digit from left
- * B= (first digit*10) + (2th digit*9) + ... (9th digit *2)
- * C= B – (B/11)*11
- * if C==0 and A==0 OK
- * if C==1 and A==1 OK
- * if C>1 and A==(C-11) OK
- *
- * @param string $check The value to check.
- *
- * @return boolean
- * @access public
- */
- function ssn($check)
- {
- $pattern = '/^\d{10}$/';
- if (!preg_match($pattern, $check)) {
- return false;
- }
-
- $sum = 0;
- $equivalent = 0;
-
- for ($i = 0; $i < 9; $i++) {
- $sum += $check{$i} * (10 - $i);
- if ($check{1} == $check{$i}) {
- $equivalent++;
- }
- }
-
- if ($equivalent == 9) {
- return false;
- }
-
- $remaining = $sum % 11;
-
- if ($remaining <= 1) {
- return (bool)($remaining == $check{9});
- }
-
- return (bool)((11 - $remaining) == $check{9});
- }
-}
View
58 package_IR.xml
@@ -1,58 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<package packagerversion="1.7.1" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
- <name>Validate_IR</name>
- <channel>pear.php.net</channel>
- <summary>Data validation class for Iran.</summary>
- <description>Package containes locale validation for IR such as:
- * Phone Number
- * Mobile Number
- * Postal Code
- * SSN (This is called "Code Melli" in Iran)
- * Persian Digits
- * Persian alphaNumeric
- * Iranian credit card
-</description>
- <lead>
- <name>Arash Hemmat</name>
- <user>arash</user>
- <email>arash.hemmat@gmail.com</email>
- <active>yes</active>
- </lead>
- <date>2011-02-06</date>
- <time>04:30:00</time>
- <version>
- <release>0.1.0</release>
- <api>0.1.0</api>
- </version>
- <stability>
- <release>alpha</release>
- <api>alpha</api>
- </stability>
- <license uri="http://www.opensource.org/licenses/bsd-license.php">BSD License</license>
- <notes>Initial release</notes>
- <contents>
- <dir name="/">
- <file name="Validate/IR.php" role="php" />
- <file name="tests/validate_IR_creditCard.phpt" role="test" />
- <file name="tests/validate_IR_alphaNumeric.phpt" role="test" />
- <file name="tests/validate_IR_mobileNumber.phpt" role="test" />
- <file name="tests/validate_IR_numeric.phpt" role="test" />
- <file name="tests/validate_IR_phoneNumber.phpt" role="test" />
- <file name="tests/validate_IR_postalCode.phpt" role="test" />
- <file name="tests/validate_IR_ssn.phpt" role="test" />
- <file name="LICENSE" role="doc" />
- </dir>
- </contents>
- <dependencies>
- <required>
- <php>
- <min>5.0.0</min>
- <max>6.0.0</max>
- </php>
- <pearinstaller>
- <min>1.9.0</min>
- </pearinstaller>
- </required>
- </dependencies>
- <phprelease />
-</package>
View
48 tests/validate_IR_alphaNumeric.phpt
@@ -1,48 +0,0 @@
---TEST--
-alphaNumeric.phpt: Unit tests for
---FILE--
-<?php
-// Validate test script
-$noYes = array('NO', 'YES');
-if (is_file(dirname(__FILE__) . '/../Validate/IR.php')) {
- require_once dirname(__FILE__) . '/../Validate/IR.php';
-} else {
- require_once 'Validate/IR.php';
-}
-
-echo "Test alphaNumeric\n";
-
-$strings = array(
- 'آزمایش ۱۲۳۴۵۶۷۸۹۰', //OK
- 'آزمایش 1234567890', //OK
- 'هِمّت بُلَند دار کِه مَردانِ روزگار اَز همّتِ بُلَند به جایی رسیده‌اَند', //OK
- '', //OK
-
- 'teststring', //NOK
- 'test1234567890', //NOK
- 'test آزمایش', //NOK
- );
-
-list($version) = explode(".", phpversion(), 2);
-foreach ($strings as $string) {
- echo "{$string}: ";
- if ((int)$version > 4) {
- try {
- echo $noYes[Validate_IR::alphaNumeric($string)]."\n";
- } catch (Exception $e) {
- echo $e->getMessage()."\n";
- }
- } else {
- echo $noYes[Validate_IR::alphaNumeric($string)]."\n";
- }
-}
-?>
---EXPECT--
-Test alphaNumeric
-آزمایش ۱۲۳۴۵۶۷۸۹۰: YES
-آزمایش 1234567890: YES
-هِمّت بُلَند دار کِه مَردانِ روزگار اَز همّتِ بُلَند به جایی رسیده‌اَند: YES
-﷼: YES
-teststring: NO
-test1234567890: NO
-test آزمایش: NO
View
44 tests/validate_IR_creditCard.phpt
@@ -1,44 +0,0 @@
---TEST--
-creditCard.phpt: Unit tests for
---FILE--
-<?php
-// Validate test script
-$noYes = array('NO', 'YES');
-if (is_file(dirname(__FILE__) . '/../Validate/IR.php')) {
- require_once dirname(__FILE__) . '/../Validate/IR.php';
-} else {
- require_once 'Validate/IR.php';
-}
-
-echo "Test creditCard\n";
-
-$strings = array(
- '1111222233334444', //OK
- '1111-2222-3333-4444', //OK
-
- 'teststring', //NOK
- '1111', //NOK
- '111-122-223-333-444-4', //NOK
- );
-
-list($version) = explode(".", phpversion(), 2);
-foreach ($strings as $string) {
- echo "{$string}: ";
- if ((int)$version > 4) {
- try {
- echo $noYes[Validate_IR::creditCard($string)]."\n";
- } catch (Exception $e) {
- echo $e->getMessage()."\n";
- }
- } else {
- echo $noYes[Validate_IR::creditCard($string)]."\n";
- }
-}
-?>
---EXPECT--
-Test creditCard
-1111222233334444: YES
-1111-2222-3333-4444: YES
-teststring: NO
-1111: NO
-111-122-223-333-444-4: NO
View
60 tests/validate_IR_mobileNumber.phpt
@@ -1,60 +0,0 @@
---TEST--
-mobileNumber.phpt: Unit tests for
---FILE--
-<?php
-// Validate test script
-$noYes = array('NO', 'YES');
-if (is_file(dirname(__FILE__) . '/../Validate/IR.php')) {
- require_once dirname(__FILE__) . '/../Validate/IR.php';
-} else {
- require_once 'Validate/IR.php';
-}
-
-echo "Test mobileNumber\n";
-
-$strings = array(
- '989123334444', //OK
- '00989353334444', //OK
- '+989363334444', //OK
- '+98 9373334444', //OK
- '(+98) 9383334444', //OK
- '+98-9323334444', //OK
-
- 'teststring', //NOK
- '999123334444', //NOK
- '+999353334444', //NOK
- '00999363334444', //NOK
- '000989373334444', //NOK
- '+00989383334444', //NOK
- '+0989323334444', //NOK
- );
-
-list($version) = explode(".", phpversion(), 2);
-foreach ($strings as $string) {
- echo "{$string}: ";
- if ((int)$version > 4) {
- try {
- echo $noYes[Validate_IR::mobileNumber($string)]."\n";
- } catch (Exception $e) {
- echo $e->getMessage()."\n";
- }
- } else {
- echo $noYes[Validate_IR::mobileNumber($string)]."\n";
- }
-}
-?>
---EXPECT--
-Test mobileNumber
-989123334444: YES
-00989353334444: YES
-+989363334444: YES
-+98 9373334444: YES
-(+98) 9383334444: YES
-+98-9323334444: YES
-teststring: NO
-999123334444: NO
-+999353334444: NO
-00999363334444: NO
-000989373334444: NO
-+00989383334444: NO
-+0989323334444: NO
View
42 tests/validate_IR_numeric.phpt
@@ -1,42 +0,0 @@
---TEST--
-numeric.phpt: Unit tests for
---FILE--
-<?php
-// Validate test script
-$noYes = array('NO', 'YES');
-if (is_file(dirname(__FILE__) . '/../Validate/IR.php')) {
- require_once dirname(__FILE__) . '/../Validate/IR.php';
-} else {
- require_once 'Validate/IR.php';
-}
-
-echo "Test numeric\n";
-
-$strings = array(
- '۱۲۳۴۵۶۷۸۹۰', //OK
-
- 'teststring', //NOK
- '1234567890', //NOK
- '١٢٣٤٥٦٧٨٩٠', //NOK
- );
-
-list($version) = explode(".", phpversion(), 2);
-foreach ($strings as $string) {
- echo "{$string}: ";
- if ((int)$version > 4) {
- try {
- echo $noYes[Validate_IR::numeric($string)]."\n";
- } catch (Exception $e) {
- echo $e->getMessage()."\n";
- }
- } else {
- echo $noYes[Validate_IR::numeric($string)]."\n";
- }
-}
-?>
---EXPECT--
-Test numeric
-۱۲۳۴۵۶۷۸۹۰: YES
-teststring: NO
-1234567890: NO
-١٢٣٤٥٦٧٨٩٠: NO
View
80 tests/validate_IR_phoneNumber.phpt
@@ -1,80 +0,0 @@
---TEST--
-mobileNumber.phpt: Unit tests for
---FILE--
-<?php
-// Validate test script
-$noYes = array('NO', 'YES');
-if (is_file(dirname(__FILE__) . '/../Validate/IR.php')) {
- require_once dirname(__FILE__) . '/../Validate/IR.php';
-} else {
- require_once 'Validate/IR.php';
-}
-
-echo "Test phoneNumber\n";
-
-$strings = array(
- '982133334444', //OK
- '00982133334444', //OK
- '+982133334444', //OK
- '+98 2133334444', //OK
- '+98 21 33334444', //OK
- '+98-21-33334444', //OK
- '(+98) (21) (33334444)', //OK
- '02133334444', //OK
- '021 33334444', //OK
- '021 33334444', //OK
- '(021) (118)', //OK
- '0411 3334444', //OK
- '(0411) (3334444)', //OK
-
- 'teststring', //NOK
- '992133334444', //NOK
- '+992133334444', //NOK
- '00992133334444', //NOK
- '000982133334444', //NOK
- '+00982133334444', //NOK
- '+0982133334444', //NOK
- '+98/21/33334444', //NOK
- '+02133334444', //NOK
- '021 22' //NOK
- );
-
-list($version) = explode(".", phpversion(), 2);
-foreach ($strings as $string) {
- echo "{$string}: ";
- if ((int)$version > 4) {
- try {
- echo $noYes[Validate_IR::phoneNumber($string)]."\n";
- } catch (Exception $e) {
- echo $e->getMessage()."\n";
- }
- } else {
- echo $noYes[Validate_IR::phoneNumber($string)]."\n";
- }
-}
-?>
---EXPECT--
-Test phoneNumber
-982133334444: YES
-00982133334444: YES
-+982133334444: YES
-+98 2133334444: YES
-+98 21 33334444: YES
-+98-21-33334444: YES
-(+98) (21) (33334444): YES
-02133334444: YES
-021 33334444: YES
-021 33334444: YES
-(021) (118): YES
-0411 3334444: YES
-(0411) (3334444): YES
-teststring: NO
-992133334444: NO
-+992133334444: NO
-00992133334444: NO
-000982133334444: NO
-+00982133334444: NO
-+0982133334444: NO
-+98/21/33334444: NO
-+02133334444: NO
-021 22: NO
View
40 tests/validate_IR_postalCode.phpt
@@ -1,40 +0,0 @@
---TEST--
-postalCode.phpt: Unit tests for
---FILE--
-<?php
-// Validate test script
-$noYes = array('NO', 'YES');
-if (is_file(dirname(__FILE__) . '/../Validate/IR.php')) {
- require_once dirname(__FILE__) . '/../Validate/IR.php';
-} else {
- require_once 'Validate/IR.php';
-}
-
-echo "Test postalCode\n";
-
-$strings = array(
- '1234567890', //OK
-
- 'teststring', //NOK
- '123456789' //NOK
- );
-
-list($version) = explode(".", phpversion(), 2);
-foreach ($strings as $string) {
- echo "{$string}: ";
- if ((int)$version > 4) {
- try {
- echo $noYes[Validate_IR::postalCode($string)]."\n";
- } catch (Exception $e) {
- echo $e->getMessage()."\n";
- }
- } else {
- echo $noYes[Validate_IR::postalCode($string)]."\n";
- }
-}
-?>
---EXPECT--
-Test postalCode
-1234567890: YES
-teststring: NO
-123456789: NO
View
50 tests/validate_IR_ssn.phpt
@@ -1,50 +0,0 @@
---TEST--
-ssn.phpt: Unit tests for
---FILE--
-<?php
-// Validate test script
-$noYes = array('NO', 'YES');
-if (is_file(dirname(__FILE__) . '/../Validate/IR.php')) {
- require_once dirname(__FILE__) . '/../Validate/IR.php';
-} else {
- require_once 'Validate/IR.php';
-}
-
-echo "Test ssn\n";
-
-$strings = array(
- '9876543210', //OK
- '1234567891', //OK
- '0324354657', //OK
-
- 'teststring', //NOK
- '1234567890', //NOK
- '3333333333', //NOK
- '0324354654', //NOK
- '12345' //NOK
- );
-
-list($version) = explode(".", phpversion(), 2);
-foreach ($strings as $string) {
- echo "{$string}: ";
- if ((int)$version > 4) {
- try {
- echo $noYes[Validate_IR::ssn($string)]."\n";
- } catch (Exception $e) {
- echo $e->getMessage()."\n";
- }
- } else {
- echo $noYes[Validate_IR::ssn($string)]."\n";
- }
-}
-?>
---EXPECT--
-Test ssn
-9876543210: YES
-1234567891: YES
-0324354657: YES
-teststring: NO
-1234567890: NO
-3333333333: NO
-0324354654: NO
-12345: NO
Please sign in to comment.
Something went wrong with that request. Please try again.