@@ -6,12 +6,12 @@ export default {
66 * Checks if a field meets the 'required' validation criteria.
77 *
88 * @param {any } value - The current value of the field.
9- * @param {Object } field - The field as specified in the form's schema.
10- * @param {Object } model - The form model.
9+ * @param {Object } _field - The field as specified in the form's schema.
10+ * @param {Object } _model - The form model.
1111 * @param {Component } fieldComponent - Field's Vue Component.
1212 * @returns {boolean } - Returns 'true' if the field is required and the value is not empty, otherwise false.
1313 */
14- required ( value , field , model , fieldComponent ) {
14+ required ( value , _field , _model , fieldComponent ) {
1515 return ! ! ( fieldComponent . isRequired && isNotEmpty ( value ) )
1616 } ,
1717
@@ -24,8 +24,68 @@ export default {
2424 * @param {Component } _fieldComponent - Field's Vue Component.
2525 * @returns {boolean } - Returns 'true' if the field is required and the value is not empty, otherwise false.
2626 */
27- string ( value , _field , _model , _fieldComponent ) {
27+ string ( value , _field , _model , _fieldComponent ) {
2828 return isString ( value )
29+ } ,
30+
31+ /**
32+ * Checks if the field's value is of type number.
33+ *
34+ * @param {any } value - The current value of the field.
35+ * @param {Object } _field - The field as specified in the form's schema.
36+ * @param {Object } _model - The form model.
37+ * @param {Component } _fieldComponent - Field's Vue Component.
38+ * @returns {boolean } - Returns 'true' if the field is a number.
39+ */
40+ number ( value , _field , _model , _fieldComponent ) {
41+ return Number . isNaN ( value )
42+ } ,
43+
44+ /**
45+ * Check if the field's value is of a valid e-mail address format.
46+ *
47+ * @param {any } value - The current value of the field.
48+ * @param {Object } _field - The field as specified in the form's schema.
49+ * @param {Object } _model - The form model.
50+ * @param {Component } _fieldComponent - Field's Vue Component.
51+ * @returns {boolean } - Returns 'true' if the field's format is a valid email format, otherwise false.
52+ */
53+ email ( value , _field , _model , _fieldComponent ) {
54+ // eslint-disable-next-line max-len
55+ const regex = new RegExp ( '^([^<>()\\[\\]\\\\.,;:\\s@"]+(?:\\.[^<>()\\[\\]\\\\.,;:\\s@"]+)*|".+")@(\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}]|(?:[a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,})$' , 'i' )
56+ return Boolean ( value . match ( regex ) )
57+ } ,
58+
59+ /**
60+ * Check if a value is a phone number in E164 or E123 format.
61+ *
62+ * @param {String } value current value of the field
63+ * @param {Object } _field - The field as specified in the form's schema.
64+ * @param {Object } _model - The form model.
65+ * @param {Component } _fieldComponent - Field's Vue Component.
66+ * @returns {boolean } - Returns 'true' if value matches the format, otherwise false.
67+ */
68+ phoneNumberE164andE123 ( value , _field , _model , _fieldComponent ) {
69+ const regex = new RegExp (
70+ // eslint-disable-next-line max-len
71+ '^\\+\\d{1,3}\\s\\d{2,3}\\s\\d{2,3}\\s\\d{4}|^\\+\\d{1,3}\\s\\d{1,14}(\\s\\d{1,13})?|^\\(\\d{3}\\)\\s\\d{3}\\s\\d{4}?' ,
72+ 'i'
73+ )
74+ return Boolean ( value . match ( regex ) )
75+ } ,
76+
77+ /**
78+ * Check if value is a valid Dutch mobile phone number
79+ *
80+ * @param {String } value current value of the field
81+ * @param {Object } _field - The field as specified in the form's schema.
82+ * @param {Object } _model - The form model.
83+ * @param {Component } _fieldComponent - Field's Vue Component.
84+ * @returns {boolean } - Returns 'true' if value matches the format, otherwise false.
85+ */
86+ mobilePhoneNL ( value , _field , _model , _fieldComponent ) {
87+ const regex = new RegExp ( '(\\+316[0-9]{8})|(06[0-9]{8})' , 'i' )
88+ return Boolean ( value . match ( regex ) )
2989 }
3090
3191
0 commit comments