Skip to content

Commit a8b40ad

Browse files
author
nicholas.carter
committed
[Inital] Inital commit
0 parents  commit a8b40ad

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Version control regex validation
2+
3+
Will validate "version numbers" using regex and preg_match.
4+
5+
Examples (With or without 'v')
6+
v1
7+
v1.1
8+
v1.132.1
9+
10+
Allows "unlimited" length MAJOR version
11+
Followed by (but not required) up to 2 addition "." - MINOR, PATCH
12+
Followed by (vut not required) "-" followed by "pre|beta|b|RC|alpha|a|pl|p" followed by -#

versionRegex.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
class VersionValidator {
3+
4+
/**
5+
* Validates a version
6+
*
7+
* @param string $version
8+
* @return bool
9+
*/
10+
11+
public static function validate($version) {
12+
return preg_match('/^([v]|)+(\d|)+(\.(\d{1,3})){0,2}+(-(pre|beta|b|RC|alpha|a|pl|p)([\.]?(\d+))?)?$/', $version);
13+
}
14+
15+
}
16+
17+
?>

0 commit comments

Comments
 (0)