I need regular expression that detect
1- any english letter or
2- any arabic letter or
3- both or
4- any number in between ( or start or end place dose not matter)
5-Maximum length can be 30.
and make sure it dose not have special characters except (they can appear any where)
@ , = % $ # & _
My Solution: I use this regular expression:
var regex = /^([a-zA-Z0-9\s@,=%$#&_\u0600-\u06FF]).{0,30}$/;
var result = regex.test('happy- - - /* */ % ! ~');
console.log(result);//prints true and it should print false because of ! and other special characters not allowed
The Problem
My solution is not correct
My References For arabic i use check here # 13 in the list Second reference Third reference
U+0600–U+06FF
/
I need regular expression that detect
1- any english letter or
2- any arabic letter or
3- both or
4- any number in between ( or start or end place dose not matter)
5-Maximum length can be 30.
and make sure it dose not have special characters except (they can appear any where)
@ , = % $ # & _
My Solution: I use this regular expression:
var regex = /^([a-zA-Z0-9\s@,=%$#&_\u0600-\u06FF]).{0,30}$/;
var result = regex.test('happy- - - /* */ % ! ~');
console.log(result);//prints true and it should print false because of ! and other special characters not allowed
The Problem
My solution is not correct
My References For arabic i use check here # 13 in the list Second reference Third reference
U+0600–U+06FF
https://jsfiddle/shareefhiasat/bdm99b1x/
Share Improve this question edited Jul 28, 2017 at 20:29 shareef asked Jul 28, 2017 at 17:05 shareefshareef 9,60116 gold badges63 silver badges94 bronze badges 5- 2 You quantified a dot. Remove the dot. – Wiktor Stribiżew Commented Jul 28, 2017 at 17:06
- Seems strange to use English characters. Do you mean Latin instead ? – user557597 Commented Jul 28, 2017 at 17:47
- @WiktorStribiżew yes i think its working why you did not post that simple answer , please do and i will accept. and for down vote ! y. – shareef Commented Jul 28, 2017 at 20:32
- Isn't it a typo? I suggest that you should remove the post. – Wiktor Stribiżew Commented Jul 28, 2017 at 20:33
-
You used the Arabic block which range from 600-6FF. But, there are more Arabic blocks.
[\p{Block=Arabic}\p{Block=Arabic_Extended_A}\p{Block=Arabic_Mathematical_Alphabetic_Symbols}\p{Block=Arabic_Presentation_Forms_A}\p{Block=Arabic_Presentation_Forms_B}\p{Block=Arabic_Supplement}]
– user557597 Commented Jul 28, 2017 at 20:51
2 Answers
Reset to default 5You just need to quantify the group, not the dot.
Here is a regex for all Arabic (Unicode 9) characters.
Note that you've just included some English characters, did you mean Latin ?
^(?:[a-zA-Z0-9\s@,=%$#&_\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDCF\uFDF0-\uFDFF\uFE70-\uFEFF]|(?:\uD802[\uDE60-\uDE9F]|\uD83B[\uDE00-\uDEFF])){0,30}$
https://jsfiddle/pydbqxgb/
Expanded
^
(?:
[a-zA-Z0-9\s@,=%$#&_\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDCF\uFDF0-\uFDFF\uFE70-\uFEFF]
|
(?:
\uD802 [\uDE60-\uDE9F]
| \uD83B [\uDE00-\uDEFF]
)
){0,30}
$
An alternative, this uses basic non-control (whitespace only) Latin.
^(?:[\u0009-\u000D\u001C-\u007E\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDCF\uFDF0-\uFDFF\uFE70-\uFEFF]|(?:\uD802[\uDE60-\uDE9F]|\uD83B[\uDE00-\uDEFF])){0,30}$
https://jsfiddle/st60dyve/
Expanded
^
(?:
[\u0009-\u000D\u001C-\u007E\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDCF\uFDF0-\uFDFF\uFE70-\uFEFF]
|
(?:
\uD802 [\uDE60-\uDE9F]
| \uD83B [\uDE00-\uDEFF]
)
){0,30}
$
simply use this Regex for alpha numeric English, Arabic and without space with minimum 5 characters.
[0-9a-zA-Z\u0600-\u06FF]