Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Extensions
UK Postcodes
Commits
7820452a
Unverified
Commit
7820452a
authored
Nov 28, 2018
by
mattwire
Committed by
GitHub
Nov 28, 2018
Browse files
Merge pull request #29 from mattwire/postcode_validation
Add functions for postcode validation
parents
ffcea415
c8b87431
Changes
1
Hide whitespace changes
Inline
Side-by-side
CRM/Civicrmpostcodelookup/Page/Postcode.php
View file @
7820452a
...
...
@@ -23,6 +23,8 @@ abstract class CRM_Civicrmpostcodelookup_Page_Postcode extends CRM_Core_Page {
* @return string
*/
protected
static
function
format
(
$postcode
,
$space
)
{
// Convert to uppercase
$postcode
=
strtoupper
(
$postcode
);
// Strip non-alpha characters
$postcode
=
preg_replace
(
'/\W/'
,
''
,
$postcode
);
if
(
strlen
(
$postcode
)
>
4
)
{
...
...
@@ -32,4 +34,16 @@ abstract class CRM_Civicrmpostcodelookup_Page_Postcode extends CRM_Core_Page {
return
$postcode
;
}
/**
* Is the provided postcode valid?
* @param $postcode
*
* @return bool
*/
protected
static
function
isValidPostcode
(
$postcode
)
{
// Regex provided by UK Gov (https://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom)
$valid
=
(
boolean
)
preg_match
(
'/^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z]))))\s?[0-9][A-Za-z]{2})$/'
,
$postcode
);
return
$valid
;
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment