kidto1412

helper

Jun 30th, 2024
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class CustomHelper {
  2.   constructor() {
  3.     // this.$q = useQuasar();
  4.   }
  5.   static passwordRule() {
  6.     return (val: any) => {
  7.       if (!/^[A-Z]/.test(val)) {
  8.         return 'Password must start with an uppercase letter'
  9.       }
  10.       if (val.length < 12) {
  11.         return 'Password must be at least 12 characters long'
  12.       }
  13.  
  14.       if (!/[a-z]/.test(val)) {
  15.         return 'Password must contain at least one lowercase letter'
  16.       }
  17.  
  18.       if (!/[!@#$%^&*(),.?":{}|<>]/.test(val)) {
  19.        return 'Password must contain at least one special character: !, @, #, $, %, ^, &, *, (, ), ,, ., ?, ", :, {, }, |, <, >'
  20.      }
  21.  
  22.      if (!/\d/.test(val)) {
  23.        return 'Password must contain at least one number'
  24.      }
  25.      return true
  26.    }
  27.  }
  28.  static emailRules(mandatory: boolean) {
  29.    console.log(mandatory, 'mandatory')
  30.    return (val: any) => {
  31.      if (mandatory == true && val.length == 0) {
  32.        return 'Email is required'
  33.      } else if (mandatory == true && val.length != 0) {
  34.        if (/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/.test(val)) {
  35.          return true
  36.        } else {
  37.          return 'Invalid Email'
  38.        }
  39.      } else if (mandatory == false && val.length == 0) {
  40.        return true
  41.      } else {
  42.        if (/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/.test(val)) {
  43.          return true
  44.        } else {
  45.          return 'Invalid Email'
  46.        }
  47.      }
  48.    }
  49.  }
  50.  // cleaned phone number
  51.  // static cleanedPhoneNum(phone: any) {
  52.  //   return phone.replace(/-/g, "");
  53.  // }
  54.  static cleanedPhoneNum(phoneNum: string): string {
  55.    return phoneNum.replace(/\D/g, '') // Pertahankan karakter angka dan tanda hubung ("-")
  56.  }
  57.  
  58.  //   phone number rules
  59.  static phoneRules() {
  60.    return (val: any) => {
  61.      const cleanedPhoneNumber = val.replace(/-/g, '')
  62.      if (cleanedPhoneNumber.length == 0) {
  63.        return 'Mobile phone number is required'
  64.      }
  65.  
  66.      if (cleanedPhoneNumber.startsWith('62')) {
  67.        if (cleanedPhoneNumber.length < 11) {
  68.          // console.log(cleanedPhoneNumber, "phone");
  69.          return 'Phone number must be at least 11 characters long'
  70.        } else {
  71.          return true
  72.        }
  73.      } else {
  74.        if (cleanedPhoneNumber.length < 10) {
  75.          return 'Phone number must be at least 10 characters long'
  76.        } else {
  77.          return true
  78.        }
  79.      }
  80.      // return true;
  81.    }
  82.  }
  83.  static convertPhoneNumber(phone: any) {
  84.    const cleanedNumber = phone.replace(/\D/g, '')
  85.    if (cleanedNumber.startsWith('62')) {
  86.      return (phone = '0' + cleanedNumber.slice(2))
  87.    } else {
  88.      return cleanedNumber
  89.    }
  90.  }
  91.  static telephoneRule() {
  92.    return (val: any) => {
  93.      const cleanedPhoneNumber = val.replace(/[\(\)\s-]+/g, '')
  94.  
  95.      if (cleanedPhoneNumber.length < 10) {
  96.        return 'Phone number must be at least 10 digits'
  97.      }
  98.      return true
  99.    }
  100.  }
  101.  //   npwp rule
  102.  static npwpRules() {
  103.    return (val: any) => {
  104.      const npwpNum = val.replace(/[\.]/g, '')
  105.  
  106.      if (npwpNum.length < 16) {
  107.        return 'NPWP  must be at least 16 number long'
  108.      }
  109.      return true
  110.    }
  111.  }
  112.  //   npwp rule
  113.  static nibRules() {
  114.    return (val: any) => {
  115.      const nibNum = val.replace(/-/g, '')
  116.      if (nibNum.length < 13) {
  117.        return 'NIB  must be at least 13 number long'
  118.      }
  119.      return true
  120.    }
  121.  }
  122.  static extractTitleFromFileName(fileName: any) {
  123.    const match = fileName.match(/(.+)-(.+)\.pdf/)
  124.    return match ? match[2] : null
  125.  }
  126. }
  127.  
  128. export default CustomHelper
  129. export const phoneNumberRegex = /^[0-9]{11,12}$/
  130.  
Add Comment
Please, Sign In to add comment