gpt-4.1-mini-2025-04-14· OpenAI
LMArena Human Preference 140K
Simple js function to detect Arabic from English script.
- User
Simple js function to detect Arabic from English script.
- Assistant
Certainly! Here's a simple JavaScript function that detects if a given string contains Arabic characters. Arabic script characters are generally in the Unicode range
\u0600to\u06FF(Arabic block), and also some extended Arabic characters in other ranges.This function checks if the input string contains any Arabic character:
function containsArabic(text) { // Arabic Unicode block ranges: // \u0600-\u06FF (Arabic) // \u0750-\u077F (Arabic Supplement) // \u08A0-\u08FF (Arabic Extended-A) // \uFB50-\uFDFF (Arabic Presentation Forms-A) // \uFE70-\uFEFF (Arabic Presentation Forms-B) const arabicRegex = /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/; return arabicRegex.test(text); } // Example usage: console.log(containsArabic("Hello")); // false console.log(containsArabic("مرحبا")); // true console.log(containsArabic("Hello مرحبا")); // trueExplanation:
- The regex looks for any character in the Arabic Unicode blocks.
- If any Arabic character is found, it returns
true. - Otherwise, it returns
false.
Let me know if you want a version that detects only English letters or distinguishes between Arabic and English more strictly!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.