Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CustomHelper {
- constructor() {
- // this.$q = useQuasar();
- }
- static passwordRule() {
- return (val: any) => {
- if (!/^[A-Z]/.test(val)) {
- return 'Password must start with an uppercase letter'
- }
- if (val.length < 12) {
- return 'Password must be at least 12 characters long'
- }
- if (!/[a-z]/.test(val)) {
- return 'Password must contain at least one lowercase letter'
- }
- if (!/[!@#$%^&*(),.?":{}|<>]/.test(val)) {
- return 'Password must contain at least one special character: !, @, #, $, %, ^, &, *, (, ), ,, ., ?, ", :, {, }, |, <, >'
- }
- if (!/\d/.test(val)) {
- return 'Password must contain at least one number'
- }
- return true
- }
- }
- static emailRules(mandatory: boolean) {
- console.log(mandatory, 'mandatory')
- return (val: any) => {
- if (mandatory == true && val.length == 0) {
- return 'Email is required'
- } else if (mandatory == true && val.length != 0) {
- if (/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/.test(val)) {
- return true
- } else {
- return 'Invalid Email'
- }
- } else if (mandatory == false && val.length == 0) {
- return true
- } else {
- if (/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/.test(val)) {
- return true
- } else {
- return 'Invalid Email'
- }
- }
- }
- }
- // cleaned phone number
- // static cleanedPhoneNum(phone: any) {
- // return phone.replace(/-/g, "");
- // }
- static cleanedPhoneNum(phoneNum: string): string {
- return phoneNum.replace(/\D/g, '') // Pertahankan karakter angka dan tanda hubung ("-")
- }
- // phone number rules
- static phoneRules() {
- return (val: any) => {
- const cleanedPhoneNumber = val.replace(/-/g, '')
- if (cleanedPhoneNumber.length == 0) {
- return 'Mobile phone number is required'
- }
- if (cleanedPhoneNumber.startsWith('62')) {
- if (cleanedPhoneNumber.length < 11) {
- // console.log(cleanedPhoneNumber, "phone");
- return 'Phone number must be at least 11 characters long'
- } else {
- return true
- }
- } else {
- if (cleanedPhoneNumber.length < 10) {
- return 'Phone number must be at least 10 characters long'
- } else {
- return true
- }
- }
- // return true;
- }
- }
- static convertPhoneNumber(phone: any) {
- const cleanedNumber = phone.replace(/\D/g, '')
- if (cleanedNumber.startsWith('62')) {
- return (phone = '0' + cleanedNumber.slice(2))
- } else {
- return cleanedNumber
- }
- }
- static telephoneRule() {
- return (val: any) => {
- const cleanedPhoneNumber = val.replace(/[\(\)\s-]+/g, '')
- if (cleanedPhoneNumber.length < 10) {
- return 'Phone number must be at least 10 digits'
- }
- return true
- }
- }
- // npwp rule
- static npwpRules() {
- return (val: any) => {
- const npwpNum = val.replace(/[\.]/g, '')
- if (npwpNum.length < 16) {
- return 'NPWP must be at least 16 number long'
- }
- return true
- }
- }
- // npwp rule
- static nibRules() {
- return (val: any) => {
- const nibNum = val.replace(/-/g, '')
- if (nibNum.length < 13) {
- return 'NIB must be at least 13 number long'
- }
- return true
- }
- }
- static extractTitleFromFileName(fileName: any) {
- const match = fileName.match(/(.+)-(.+)\.pdf/)
- return match ? match[2] : null
- }
- }
- export default CustomHelper
- export const phoneNumberRegex = /^[0-9]{11,12}$/
Add Comment
Please, Sign In to add comment