Skip to content

Instantly share code, notes, and snippets.

@ridvanaltun
Created August 11, 2021 04:56
Show Gist options
  • Save ridvanaltun/5aacb7462388da5f56ea3cdeb6b88cd9 to your computer and use it in GitHub Desktop.
Save ridvanaltun/5aacb7462388da5f56ea3cdeb6b88cd9 to your computer and use it in GitHub Desktop.
Regex

Regex List

// Phone Number
function mobilePhoneRegEx(val) {
    return /^(05)([0-9]{2})\s?([0-9]{3})\s?([0-9]{2})\s?([0-9]{2})$/.test(val);
    /*
    05231231212
    0523 123 12 12
    */
}

// Fixed Phone Number
function phoneRegEx(val) {
    return /^(0)([0-9]{3})\s?([0-9]{3})\s?([0-9]{2})\s?([0-9]{2})$/.test(val);
    /*
    01231231212
    0123 123 12 12
    */
}

// TC Identification Number
function IdNumberRegEx(val) {
    return /^[1-9]{1}[0-9]{9}[02468]{1}$/.test(val);
    /*
    12345678901
    */
}

// Tax Number
function taxNoRegEx(val) {
    return /^[0-9]{10}$/.test(val);
    /*
    1234567890
    */
}

// Credit Card Number
function creditCardRegEx(val) {
    return /^([0-9]{4})\s?([0-9]{4})\s?([0-9]{4})\s?([0-9]{4})$/.test(val);
    /*
    1111222233334444
    1111 2222 3333 4444
    */
}

// Car Plate
function carPlateRegEx(val) {
    return /^(0[1-9]|[1-7][0-9]|8[01])(([A-Z])(\d{4,5})|([A-Z]{2})(\d{3,4})|([A-Z]{3})(\d{2,3}))$/.test(val);
    /*
    34A2344
    36A23415
    06BK123
    08JK1234
    81ABC75
    */
}

// Date of Birth
function birthdayRegEx(val) {
    return /^([1-9]|[12][0-9]|3[01])(\/?\.?\-?\s?)(0[1-9]|1[12])(\/?\.?\-?\s?)(19[0-9][0-9]|20[0][0-9]|20[1][0-8])$/.test(val);
    /*
    13.08.1987
    13081987
    13/08/1987
    13-08-1987
    13 08 1987
    */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment