Skip to content

Commit f8c5927

Browse files
committed
added alphanumeric validator
1 parent 279c195 commit f8c5927

File tree

9 files changed

+77
-12
lines changed

9 files changed

+77
-12
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ So what has changed since version 1.x?
5353
* **domain***domain.com*
5454
* **number***float/negative/positive*
5555
* **date***yyyy-mm-dd (format can be customized, more information below)*
56+
* **alphanumeric***with support for defining additional characters*
5657
* **length***min/max/range*
5758
* **required***no validation except that a value has to be given*
5859
* **custom***Validate value against regexp*

form-validator/date.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*
1414
* @license Dual licensed under the MIT or GPL Version 2 licenses
15-
* @version 1.9.29
15+
* @version 1.9.30
1616
*/
1717
(function($) {
1818

form-validator/jquery.form-validator.js

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Documentation and issue tracking on Github <https://github.com/victorjonsson/jQuery-Form-Validator/>
66
*
77
* @license Dual licensed under the MIT or GPL Version 2 licenses
8-
* @version 1.9.29
8+
* @version 1.9.30
99
*/
1010
(function($) {
1111

@@ -1011,15 +1011,16 @@
10111011
badLength : 'You have to give an answer between ',
10121012
notConfirmed : 'Values could not be confirmed',
10131013
badDomain : 'Incorrect domain value',
1014-
badUrl : 'Incorrect url value',
1015-
badFloat : 'Incorrect float value',
1014+
badUrl : 'The answer you gave was not a correct URL',
10161015
badCustomVal : 'You gave an incorrect answer',
1017-
badInt : 'Incorrect integer value',
1016+
badInt : 'The answer you gave was not a correct number',
10181017
badSecurityNumber : 'Your social security number was incorrect',
10191018
badUKVatAnswer : 'Incorrect UK VAT Number',
10201019
badStrength : 'The password isn\'t strong enough',
10211020
badNumberOfSelectedOptionsStart : 'You have to choose at least ',
1022-
badNumberOfSelectedOptionsEnd : ' answers'
1021+
badNumberOfSelectedOptionsEnd : ' answers',
1022+
badAlphaNumeric : 'The answer you gave must contain only alphanumeric characters ',
1023+
badAlphaNumericExtra: ' and '
10231024
}
10241025
};
10251026

@@ -1250,6 +1251,36 @@
12501251
errorMessageKey: 'badInt'
12511252
});
12521253

1254+
/*
1255+
* Validate alpha numeric
1256+
*/
1257+
$.formUtils.addValidator({
1258+
name : 'validate_alphanumeric',
1259+
validate : function(val, $el, config, language) {
1260+
var patternStart = '^([a-zA-Z0-9',
1261+
patternEnd = ']+)$',
1262+
additionalChars = $el.attr('data-validation-allowing'),
1263+
pattern = '';
1264+
1265+
if( additionalChars ) {
1266+
pattern = patternStart + additionalChars + patternEnd;
1267+
var extra = additionalChars.replace(/\\/g, '');
1268+
if( extra.indexOf(' ') > -1 ) {
1269+
extra = extra.replace(' ', '');
1270+
extra += ' and spaces ';
1271+
}
1272+
this.errorMessage = language.badAlphaNumeric + language.badAlphaNumericExtra + extra;
1273+
} else {
1274+
pattern = patternStart + patternEnd;
1275+
this.errorMessage = language.badAlphaNumeric;
1276+
}
1277+
1278+
return new RegExp(pattern).test(val);
1279+
},
1280+
errorMessage : '',
1281+
errorMessageKey: ''
1282+
});
1283+
12531284
/*
12541285
* Validate against regexp
12551286
*/

form-validator/jquery.form-validator.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

form-validator/location.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* @license Dual licensed under the MIT or GPL Version 2 licenses
14-
* @version 1.9.29
14+
* @version 1.9.30
1515
*/
1616
(function($) {
1717

form-validator/security.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* - validate_backend
1313
*
1414
* @license Dual licensed under the MIT or GPL Version 2 licenses
15-
* @version 1.9.29
15+
* @version 1.9.30
1616
*/
1717
(function($) {
1818

form-validator/sweden.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* - validate_swephone
1414
*
1515
* @license Dual licensed under the MIT or GPL Version 2 licenses
16-
* @version 1.9.29
16+
* @version 1.9.30
1717
*/
1818
(function($) {
1919

form-validator/test.html

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@
2222
<strong>Swedish county suggestions</strong><br />
2323
<input id="swedish-county-suggestions" data-suggestions="Monkey, Horse, Fox, Tiger, Elephant">
2424
</p>
25+
<p>
26+
<strong>Display password strength</strong><br />
27+
<input type="password" id="password">
28+
</p>
29+
<p>
30+
<strong>Alphanumeric and -_</strong><br>
31+
<input name="test" data-validation="alphanumeric" data-validation-allowing="-_ ">
32+
</p>
33+
<p>
34+
<input type="submit">
35+
</p>
2536
</form>
2637
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
2738
<script src="jquery.form-validator.js"></script>
@@ -170,6 +181,27 @@
170181
});
171182
});
172183

184+
/*
185+
* ALPHANUMERIC VALIDATION
186+
*/
187+
test("Alphanumeric validation", function() {
188+
189+
clearForm();
190+
191+
var links = [
192+
{val:'a', isValid:true},
193+
{val:'asdvs1', isValid:true},
194+
{val:'a b', isValid:false},
195+
{val:'a-_ bäöåA', isValid:false},
196+
{val:input('a b', {'allowing':' ', '':'alphanumeric'}), isValid:true},
197+
{val:input('a-_ bäöåÖA', {'allowing':' -_öäåÄÖÅ', '':'alphanumeric'}), isValid:true}
198+
];
199+
200+
$.each(links, function(i, obj) {
201+
runTest(obj, 'alphanumeric');
202+
});
203+
});
204+
173205
/*
174206
* NUMBER VALIDATION
175207
*/
@@ -232,6 +264,7 @@
232264
$('#test-form').addSuggestions();
233265
$('#country-suggestions').suggestCountry();
234266
$('#swedish-county-suggestions').suggestSwedishCounty();
267+
$('#password').displayPasswordStrength();
235268
});
236269

237270
$.formUtils.loadModules('date'+dev+', location'+dev+', security'+dev+', sweden'+dev+', uk'+dev+'');

form-validator/uk.dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* - validate_ukvatnumber
1010
*
1111
* @license Dual licensed under the MIT or GPL Version 2 licenses
12-
* @version 1.9.29
12+
* @version 1.9.30
1313
*/
1414
$.formUtils.addValidator({
1515
name : 'validate_ukvatnumber',

0 commit comments

Comments
 (0)