Skip to content

Commit

Permalink
fix: use stricter regex matching
Browse files Browse the repository at this point in the history
  • Loading branch information
mantariksh committed Jun 15, 2021
1 parent 3c612a3 commit 7c66b8b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/shared/util/uen-validation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import validator from 'validator'

/**
* Validate entity-type indicators, as per
* https://www.uen.gov.sg/ueninternet/faces/pages/admin/aboutUEN.jspx
Expand Down Expand Up @@ -50,7 +48,14 @@ const VALID_ENTITY_TYPE_INDICATORS = new Set([
* @param s String
* @returns True if string is numeric
*/
const isNumeric = (s: string): boolean => !isNaN(Number(s))
const isNumeric = (s: string): boolean => !!s.match(/^[0-9]+$/)

/**
* Helper to check whether a string is alphabetic
* @param s string
* @returns True if string is alphabetic
*/
const isAlphabetic = (s: string): boolean => !!s.match(/^[a-zA-Z]+$/)

/**
* Validates whether a provided string value adheres to the UIN/FIN format
Expand All @@ -70,7 +75,7 @@ export const isUenValid = (uen: string): boolean => {
if (uen.length === 9) {
// check that last character is a letter
const lastChar = uen[uen.length - 1]
if (!validator.isAlpha(lastChar)) {
if (!isAlphabetic(lastChar)) {
return false
}

Expand All @@ -87,7 +92,7 @@ export const isUenValid = (uen: string): boolean => {
// Length is 10
// check that last character is a letter
const lastChar = uen[uen.length - 1]
if (!validator.isAlpha(lastChar)) {
if (!isAlphabetic(lastChar)) {
return false
}

Expand Down

0 comments on commit 7c66b8b

Please sign in to comment.