Skip to content

Commit

Permalink
Merge pull request #12 from Misioka/master
Browse files Browse the repository at this point in the history
Fix regexp validation
  • Loading branch information
devx-agency-deprecated authored Apr 13, 2021
2 parents f49a218 + dc5606c commit 3cae6b1
Show file tree
Hide file tree
Showing 3 changed files with 2,198 additions and 1,556 deletions.
14 changes: 7 additions & 7 deletions lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ export const validateEmail = (value: string): boolean => {
if (!value)
return true

return /^(([^<>()\[\]\\.,;:\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,}))$/.test(value)
return /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([\\D\-0-9]+\.)+\\D{2,}))$/.test(value)
}

/**
* @description Validate phone format
*/
export const validatePhone = (value: string, prefixRequired?: boolean = false): boolean => {
export const validatePhone = (value: string, prefixRequired: boolean = false): boolean => {
if (!value)
return true

Expand All @@ -55,7 +55,7 @@ export const validateZipCode = (value: string): boolean => {
if (!value)
return true

const regexValid = /^[1-9]{1}\d{2}[ ]?\d{2}$/.test(value.trim())
const regexValid = /^[1-9]\d{2}[ ]?\d{2}$/.test(value.trim())
if (regexValid) {
const firstChar = value[0]

Expand All @@ -78,7 +78,7 @@ export const validateStreet = (value: string): boolean => {
if (!value)
return true

return /^[0-9a-žA-Ž-,.\/ ]+$/.test(value.trim())
return /^[0-9\\D\-,.\/ ]+$/.test(value.trim())
}

/**
Expand All @@ -88,7 +88,7 @@ export const validateCity = (value: string): boolean => {
if (!value)
return true

return /^[0-9a-žA-Ž- ]+$/.test(value.trim())
return /^[0-9\\D\- ]+$/.test(value.trim())
}

/**
Expand All @@ -98,7 +98,7 @@ export const validateSurname = (value: string): boolean => {
if (!value)
return true

return /^[a-žA-Ž]+$/.test(value.trim())
return /^\\D+$/.test(value.trim())
}

/**
Expand All @@ -108,7 +108,7 @@ export const validateLandRegistryNumber = (value: string): boolean => {
if (!value)
return true

return /^((?!(\W))[0]*[0\W]*[a-zA-Z1-9]+.*)$/.test(value.trim())
return /^((?!(\W))[0]*[0\W]*[\\D1-9]+.*)$/.test(value.trim())
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "devx-js-utilities",
"version": "0.1.5",
"version": "0.1.6",
"main": "dist/index.js",
"scripts": {
"build": "babel lib --out-dir dist",
Expand Down
Loading

0 comments on commit 3cae6b1

Please sign in to comment.