All files / utils validate.ts

83.78% Statements 31/37
76% Branches 19/25
77.77% Functions 14/18
83.78% Lines 31/37

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 371x 5x 5x 1x 1x 1x 1x 1x 1x     1x 1x 5x 5x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x         1x 1x 1x 1x
export function requiredRules(v:any) {
    return !!v || "This field cannot be empty"
  } 
 
  export function selectRequiredRules(v:any) {
    return Object.entries(v).length > 0 || "This field cannot be empty"
  } 
  
  export function zeroAtStartRules(v:any) {
    return !/^0/.test(v) || "Can't put 0 at the start"
  }
  
  export function lenghthRules(v:any, min:number,  max:number) {
    let output = min == max ? `Please input only ${min} characters` : min === 0 ? `Please input max ${max} characters` : `Please input between ${min} and ${max} character`
    return v.length >= min && v.length <= max || output
  }
  
  export function alphabetOnlyRules(v:any) {
    return /^[a-zA-Z ]*$/.test(v) || "Please alpabet"
  } 
  
  export function trimSpace(v:any){
    return /^[^\s]+(\s+[^\s]+)*$/.test(v) || "Can't put whitespace at the start and the end"
  }
  export function preventEmoticon(v:any){
    return /^[ A-Za-z0-9_,./&+-@#$%^(){}"'|:;=`?!*~]*$/.test(v) || 'cant accept emoticon'
}
 
export function validEmailRules(v:any) {
  return /^[-!#$%&'*+\/0-9=?A-Z^_a-z{|}~](\.?[-!#$%&'*+\/0-9=?A-Z^_a-z`{|}~])*@[a-zA-Z0-9](-*\.?[a-zA-Z0-9])*\.[a-zA-Z](-?[a-zA-Z0-9])+$/.test(
    v
  ) || 'Please input valid email'
}
 
export function numberOnlyRules(v:any) {
  return /^[0-9]+$/.test(v) || "Please only enter numeric characters only! (Allowed input:0-9)"
}