From 6986e6f7daf9ab92cbe58696c06a25ea9575c645 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Mon, 10 Mar 2014 10:05:57 -0500 Subject: [PATCH] oops: Allow digits in usernames --- include/class.validator.php | 2 +- setup/test/tests/test.validation.php | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 setup/test/tests/test.validation.php diff --git a/include/class.validator.php b/include/class.validator.php index 171f85f22..62ce68153 100644 --- a/include/class.validator.php +++ b/include/class.validator.php @@ -173,7 +173,7 @@ class Validator { function is_username($username, &$error='') { if (strlen($username)<2) $error = 'At least two (2) characters'; - elseif (!preg_match('/^[\p{L}._-]+$/u', $username)) + elseif (!preg_match('/^[\p{L}\d._-]+$/u', $username)) $error = 'Username contains invalid characters'; return $error == ''; } diff --git a/setup/test/tests/test.validation.php b/setup/test/tests/test.validation.php new file mode 100644 index 000000000..942767329 --- /dev/null +++ b/setup/test/tests/test.validation.php @@ -0,0 +1,21 @@ +<?php + +require_once INCLUDE_DIR.'class.validator.php'; + +class TestValidation extends Test { + var $name = "Validation checks"; + + function testValidUsernames() { + // Ascii + $this->assert(Validator::is_username('jared')); + $this->assert(Validator::is_username('jared12')); + // Unicode + $this->assert(Validator::is_username('järed')); + $this->assert(Validator::is_username('järed12')); + $this->assert(Validator::is_username('中国期刊全文数据')); + // Non-letters + $this->assert(!Validator::is_username('j®red')); + } +} +return 'TestValidation'; +?> -- GitLab