user7134448
user7134448

Reputation:

Validate name in form with accents jquery

So I have to validate the name in a form, a few of validations are:

I was trying to use a regular expression like this:

 /^(?=.{5,50}$)\p{L}*(?: \p{L}+)*?/;

But javascript doesn't allow unicode expressions, I cannot use plugins as XRegExp, also I have tried:

    /^[a-z\u00E0-\u00FC]+$/i

and

    /^[A-Za-z-áéíóú]+$/

Any help?

Thank you for reading :)

Upvotes: 2

Views: 1624

Answers (1)

m87
m87

Reputation: 4523

You may use the following regex :

[a-z \u00E0-\u00FC]{5,50}

see regex demo

JavaScript

var names = ['áéíóúÁÉÍÓÚ', 'adádÚ', 'abcd', 'de fg'];
names.forEach(function(e) {
  var valid = 'Validating "' + e + '"... | ' + /[a-z \u00E0-\u00FC]{5,50}/i.test(e);
  console.log(valid);
});

Upvotes: 3

Related Questions