public function PhoneFieldValidationRule::phone_countries in Field Validation 8
2 calls to PhoneFieldValidationRule::phone_countries()
- PhoneFieldValidationRule::buildConfigurationForm in src/
Plugin/ FieldValidationRule/ PhoneFieldValidationRule.php - Form constructor.
- PhoneFieldValidationRule::validate in src/
Plugin/ FieldValidationRule/ PhoneFieldValidationRule.php
File
- src/
Plugin/ FieldValidationRule/ PhoneFieldValidationRule.php, line 96
Class
- PhoneFieldValidationRule
- PhoneFieldValidationRule.
Namespace
Drupal\field_validation\Plugin\FieldValidationRuleCode
public function phone_countries() {
$countries = [
'fr' => [
'name' => $this
->t('France'),
'regex' => '/(\\+33|0)([1-9]\\d{8}|85\\d{7}|87[0-57-9]\\d{6})$/',
],
'be' => [
'name' => $this
->t('Belgium'),
'regex' => '/^(\\+32|0)[1-9]\\d{7,8}$/i',
],
'it' => [
'name' => $this
->t('Italy'),
'regex' => "/^(\\+39)?[ ]?([0-9]{2,3}(\\/|-| )?[0-9]{6,7})\$/i",
],
'el' => [
'name' => $this
->t('Greece'),
'regex' => "/^(\\+30)?[ ]?([0-9]{3,4}(\\/|-| )?[0-9]{6,7})\$/i",
],
'ch' => [
'name' => $this
->t('Switzerland'),
'regex' => "%(\\+41|0|0041)([2-9]\\d{8})\$%",
],
'ca' => [
'name' => $this
->t('US & Canada'),
'regex' => '/\\D*(\\d*)\\D*[2-9][0-8]\\d\\D*[2-9]\\d{2}\\D*\\d{4}\\D*\\d*\\D*/x',
],
'cr' => [
'name' => $this
->t('Costa Rica'),
'regex' => "/(00)?[\\s|-]?((\\+)?[\\s|-]?[0-9]{3})?[\\s|-]?([0-9]{2})[\\s|-]?([0-9]{2})[\\s|-]?([0-9]{2})[\\s|-]?([0-9]{2})[\\s|-]?/",
],
'pa' => [
'name' => $this
->t('Panama'),
'regex' => '/((00|\\+)?[0-9]{3}[\\s])?([0-9]{3,4})[\\s|-]?([0-9]{4})/',
],
'gb' => [
'name' => $this
->t('Great Britain - United Kingdom'),
'regex' => "/((^\\+44\\s?(\\(0\\))?\\d{4}|^\\(?0\\d{4}\\)?){1}\\s?\\d{3}\\s?\\d{3}|(^\\+44\\s?(\\(0\\))?\\d{3}|^\\(?0\\d{3}\\)?){1}\\s?\\d{3}\\s?\\d{4}|(^\\+44\\s?(\\(0\\))?\\d{2}|^\\(?0\\d{2}\\)?){1}\\s?\\d{4}\\s?\\d{4}|(^\\+44\\s?(\\(0\\))?\\d{1}|^\\(?0\\d{1}\\)?){1}\\s?\\d{5}\\s?\\d{5})(\\s?\\#\\d*)?/x",
],
'ru' => [
'name' => $this
->t('Russia'),
'regex' => "/^\\D*[78]?\\D*\\d{3,5}\\D*\\d{1,3}\\D*\\d{2}\\D*\\d{2}\\D*/x",
],
/*
'ua' => [
'name' => t('Ukraine'),
'regex' => '',
], */
'es' => [
'name' => $this
->t('Spain'),
'regex' => '/^[0-9]{2,3}-? ?[0-9]{6,7}$/',
],
/*
'au' => [
'name' => t('Australia'),
'regex' => '',
], */
'cs' => [
'name' => $this
->t('Czech Republic'),
'regex' => '/^((?:\\+|00)420)? ?(\\d{3}) ?(\\d{3}) ?(\\d{3})$/',
],
'hu' => [
'name' => $this
->t('Poland - mobiles only'),
'regex' => "/^\\D*(?:\\+?36|06)?(\\d\\d?)\\D*(\\d{3})\\D*(\\d{3,4})\\D*\$/x",
],
'pl' => [
'name' => $this
->t('Poland'),
'regex' => "/^(\\+48\\s+)?\\d{3}(\\s*|\\-)\\d{3}(\\s*|\\-)\\d{3}\$/i",
],
'nl' => [
'name' => $this
->t('Netherland'),
'regex' => '/([0]{1}[6]{1}[-\\s]+[1-9]{1}[\\s]*([0-9]{1}[\\s]*){7})|([0]{1}[1-9]{1}[0-9]{2}[-\\s]+[1-9]{1}[\\s]*([0-9]{1}[\\s]*){5})|([0]{1}[1-9]{1}[0-9]{1}[-\\s]+[1-9]{1}[\\s]*([0-9]{1}[\\s]*){6})/x',
],
'se' => [
'name' => $this
->t('Sweden'),
'regex' => "/^(([+]\\d{2}[ ][1-9]\\d{0,2}[ ])|([0]\\d{1,3}[-]))((\\d{2}([ ]\\d{2}){2})|(\\d{3}([ ]\\d{3})*([ ]\\d{2})+))\$/i",
],
'za' => [
'name' => $this
->t('South Africa'),
'regex' => '/^((?:\\+27|27)|0)[ ]*((\\d{2})(-| )?(\\d{3})(-| )?(\\d{4})|(\\d{2})( |-)(\\d{7}))$/',
],
/*
'il' => [
'name' => t('Israel'),
'regex' => '',
], */
/*
'nz' => [
'name' => t('New Zealand'),
'regex' => '',
], */
'br' => [
'name' => $this
->t('Brazil'),
'regex' => "/^(\\+|0{2}|)?(55|0|)[ -.]?((\\(0?[1-9][0-9]\\))|(0?[1-9][0-9]))[ -.]?([1-9][0-9]{2,3})[ -.]?([0-9]{4})\$/",
],
'cl' => [
'name' => $this
->t('Chile'),
'regex' => "/^((\\(\\d{3}\\) ?)|(\\d{3}-)|(\\(\\d{2}\\) ?)|(\\d{2}-)|(\\(\\d{1}\\) ?)|(\\d{1}-))?\\d{3}-(\\d{3}|\\d{4})\$/i",
],
'cn' => [
'name' => $this
->t('China'),
'regex' => '/^(\\+86|86)?( |-)?([0-9]{11}|([0-9]{3,4}(\\-|\\.| )[0-9]{3,8})|[0-9]{2}( |\\-)[0-9]{4}[ ][0-9]{4}|[0-9]{2}\\.[0-9]{2}\\.[0-9]{2}\\.[0-9]{2}\\.[0-9]{2})$/',
],
/*
'hk' => [
'name' => t('Hong-Kong'),
'regex' => '',
],
'mo' => [
'name' => t('Macao'),
'regex' => '',
], */
'ph' => [
'name' => $this
->t('The Philippines'),
'regex' => "/((^\\+63\\s?\\(?\\d{5}\\)?|^\\(?\\d{5}\\)?){1}\\s?\\d{3}(\\S?|\\s?)?\\d{4}|(^\\+63\\s?\\(?\\d{4}\\)?|^\\(?\\d{4}\\)?){1}\\s?\\d{3}(\\S?|\\s?)?\\d{4}|(^\\+63\\s?\\(?\\d{3}\\)?|^\\(?\\d{3}\\)?){1}\\s?\\d{3}(\\S?|\\s?)?\\d{4}|(^\\+63\\s?\\(?\\d{2}\\)?|^\\(?\\d{2}\\)?){1}\\s?\\d{3}(\\S?|\\s?)?\\d{4}|(^\\+63\\s?\\(?\\d{1}\\)?|^\\(?\\d{1}\\)?){1}\\s?\\d{3}(\\S?|\\s?)?\\d{4})(\\s?\\#\\d*)?/x",
],
'sg' => [
'name' => $this
->t('Singapore'),
'regex' => '/^(\\+65)?\\s?[689]\\d{7}$/i',
],
'jo' => [
'name' => $this
->t('Jordan'),
'regex' => "/(^(\\+962|00962|962|0)[-\\s]{0,1}[7]{1}[7-9]{1}[0-9]{7}\$) | (^(\\+962|00962|962|0)[-\\s]{0,1}[2-6][-\\s]{0,1}[0-9]{7}\$)/x",
],
/*
'eg' => [
'name' => t('Egypt'),
'regex' => '',
], */
'pk' => [
'name' => $this
->t('Pakistan'),
'regex' => "/^(\\+)?([9]{1}[2]{1})?-? ?(\\()?([0]{1})?[1-9]{2,4}(\\))?-? ??(\\()?[1-9]{4,7}(\\))?\$/i",
],
'in' => [
'name' => $this
->t('India'),
'regex' => "/^((\\+*)((0[ -]+)*|(91 )*)(\\d{12}+|\\d{10}+))|\\d{5}([- ]*)\\d{6}\$/i",
],
'dk' => [
'name' => $this
->t('Denmark'),
'regex' => "/^(([+]\\d{2}[ ][1-9]\\d{0,2}[ ])|([0]\\d{1,3}[-]))((\\d{2}([ ]\\d{2}){2})|(\\d{3}([ ]\\d{3})*([ ]\\d{2})+))\$/i",
],
];
return $countries;
}