Search code examples
regexregex-lookaroundsregex-groupregex-negationregex-greedy

Regex to allow only alphabet and special alphabets like é


I want a regex which only allows a-z A-Z and special characters like é (accented). I don't want any special characters like @,.$%^&"

lastName.addEventListener(
    'keyup',
    inputValidation.bind({
        // reg: /^[A-Za-z ]+$/,
        reg: /^[a-zA-Z]*$/,
        element: lastName,
        error: 'Only alphabets allowed!',
    })
);

I have tried many regex but they also restrict characters like é. I want to allow special alphabets and simple alphabets


Solution

  • Try

    lastName.addEventListener(
        'keyup',
        inputValidation.bind({
            reg: /^[a-zA-ZÀ-ÖØ-öø-ÿ]*$/,
            element: lastName,
            error: 'Only alphabets allowed!',
        })
    );