Search code examples
c#validationstored-proceduresnumbersarabic

Check Text field to block Arabic numbers using C# or SQL Server Stored Procedure


How to check if the visitor entered any Arabic numbers like (۱, ۲, ۳)

Example: "Hi ۱ Sir, OK ۲ ۳ Thanks" in the "Text field" or "Text area" using C# (MVC or Core) or by using SQL Server Stored Procedure?

Note that I send the value via API using Ajax to the Controller, so I can process it in C# or send it to SQL Server Procedure to check it, and if it has Arabic numbers then return True or False.

I found many solutions in JavaScript but the visitor can pass it easily in browser console:

checkAR = function(){return false};

Please Advise.


Solution

  • for C#

    static bool CheckArabicWords(string arabicText)
            {
                Regex regex = new Regex("[\u0600-\u06FF]");
                return regex.IsMatch(arabicText);
    
            }
    

    for sql

    Create Function [dbo].[IsArabic] (@text varchar(max))
    Returns bit
    as
    begin
    if(@text like '%[أ-ي]%')
    return 1;
    return 0;
    end