Allowing non-latin characters with regex [duplicate] - javascript

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Regular expression to match non-english characters?
I am using this regex to limit some characters.
I wanted to change this to allow all latin and non-latin letters but i think regex is not my think : )
String.prototype.isText2 = function () {return /^[\.\-\w\s&']*$/.test(this)}
This regex only allows latin chars and ' and & i think.
How can i make it allow non-latin letters ? (like these ç,ü,ğ,ş and chinese,japanese, arabic)

You can use XRegExp. This supports Unicode.

You will need to work with unicode values. Please take a look at this previous SO thread for more information.

Related

Why is my regex allowing unspecified characters? JavaScript [duplicate]

This question already has answers here:
Why do regex constructors need to be double escaped?
(5 answers)
Difference between regex [A-z] and [a-zA-Z]
(6 answers)
Regular expression works on regex101.com, but not on prod
(1 answer)
Closed 2 years ago.
I know this question has been asked a few times and the answers are unique to the specific regexes in question, but aside from that, I've tried to make sure that I'm escaping characters that have special meaning. Whilst this regex plays ball on https://regex101.com (in JavaScript mode), in my app it's having other ideas!
^([A-z0-9][A-z0-9 '\-,\.:\&]{0,245}[A-z0-9]|[A-z0-9][A-z0-9 '\-,\.:\&]{1,244}[A-z0-9])$
This is what I tell the user: 2-247 characters, start and end with A-z 0-9, permitted special characters: ' - , . : &
...but as you see, I'm actually also ensuring that the string starts with:
a) Two non-special characters, or
b) One non-special character followed by a special character, as long as that special character is followed by one or more non-special characters.
This is how I'm implementing the regex:
var nameRegex = new RegExp("^([A-z0-9][A-z0-9 '\-,\.:&]{0,245}[A-z0-9]|[A-z0-9][A-z0-9 '\-,\.:&]{1,244}[A-z0-9])$");
if (!nameRegex.test(formElements[i].value)) {
// validation stuff here
}
Everything the regex intends on doing, it does. I've tested every condition that I'm checking for. But it does more. Regex 101 disallows a string like d*d, but my app? Perfectly fine.
I'll try .match instead of .test, maybe .test isn't the tool I think I need for this job?

Regex special characters by ascii [duplicate]

This question already has answers here:
How do I use a Regex to replace non-alphanumeric characters with white space?
(1 answer)
Check for special characters in string
(12 answers)
Closed 3 years ago.
I have to use regex for my password validation that include special characters at least one.
https://en.wikipedia.org/wiki/ASCII
export const passwordValidation = password => {
const regPassword = /^(?=.*?[#?!#$%^&*-]).{8,}$/
return regPassword.test(password)
}
I tried this way but I think this isn't good way.
Is there other way to check all special characters by ascii code except alphanumeric ?
First, you need to define what a "special" character is. Do you mean anything not in the range A-Z (English alphabet)? A-Z and 0-9? Something else? Then you either use a character class listing the ones you want, which is what you've done, or a negated class saying you want something other than what's in the class:
return /^(?=.*?[^a-z0-9]).{8,}$/i.test(password);
// ^---- negated

How can I use Regular Expression to match Chinese characters like ,。‘;’ [duplicate]

This question already has answers here:
Regular expression to match non-ASCII characters?
(8 answers)
Closed 5 years ago.
I'm using javascript to convert string to what I want!!
Can I use Regular Expression and use what Regular Expression??
Is there anyone that can help me?
First, you need to get corresponding Unicode code for these Chinese characters. Here is a helpful tool.
character code(base 10) code(hex)
, 65307 0xff1b
。 65292 0xff0c
; 12290 0x3002
Second, use these Unicode code to form regexp.
js:
/[\u3002\uff0c\uff1b]/.test('A string contains Chinese character。')
true

Regex for alphanumerical characters but also other alphabets such as Chinese, Japanese, Cyrillic [duplicate]

This question already has answers here:
Regular expression with the cyrillic alphabet
(4 answers)
Closed 6 years ago.
my knowledge with Regex is limited and I'm trying to keep the text of the following sentence but remove the special characters such as dashes:
Λένα & Πλάτωνος - Red Axes Remixes
Sugai Ken 鯰上 - On The Quakefish
Anyone knows how to deal with different alphabets?
I tried ([^\w'])+ but it removes the essential characters...
Thanks!
You could try something like this:
`[^\x00-\x1F\x21-\x7F]*
This should match anything not in the regular ascii set and space. You can update that to include whatever other regualar ascii characters you would like to include. As you can see, I have 1 ranges, so that it includes the 'space' character.
Obviously, you could go the other way around and do an inclusive match, making it easier to include the exact characters to match:
`[\x80-\x{FFFF} &]*

validation using \p{L} in JavaScript regexp [duplicate]

This question already has answers here:
Match only unicode letters
(3 answers)
Closed 4 years ago.
**var pattern = /^[\p{L}0-9 ##'!&(),\[\].+/-]{1,100}$/;** \\first of all I din understand this pattern. someone plz explain it to me\\
if (!pattern.test(Name))
{
alert('Account Name must not contain the given values');
Xrm.Page.getAttribute("name").setValue("");
return false;
}
else
{
return true;
}
when I give this as validation it is throwing error message for all the values I enter. So I need some explanation on the pattern which I think will solve the rest.
In Javascript, the sequence \p{L} (in a character class) has no special meaning; it simply means the letter p or the letter { or the character L or the character }. You're probably getting confused with XRegExp, another library, or another language's (eg Perl, PHP, .NET etc.) implementation of regexps, which support so-called Unicode character categories.
Change
/^[\p{L}0-9 ##'!&(),\[\].+/-]{1,100}$/
to
/^[\p{L}0-9 ##'!&(),\[\].+\/-]{1,100}$/
^^
since you have to escape slashes / since you have defined them to be delimiters.
The meaning of the regex is that your entire string has to be between 1 and 100 characters of the listed characters, numbers and letters.

Categories

Resources