Question

this is the case

passes:

 "אבגדהו"
 "אב'גדהו"
 "אב-גדהו"
 "אב"גד"
 "אבגדהו"
 "אב.גד"
 "אבגדהו"

fails :

"א*בAb"
"א/ב1c"

trying the code below i am getting starnge behavior that as soon as the first fail test all the following that suppose to pass fail also

so the question is using c# winforms desktop app , what is the right way to validate string

will contain only א TO ת
will allow to contain chars .-' if string contains anywhere within it a numeric, or any other language chars = fail

    public string OnlyHebPlusSomeSpclChars(string StrToVerify)
    {

        bool ISheb = StrToVerify.All(c => c >= 0x0580 && c <= 0x05ff);
        if (ISheb)
        {
            return StrToVerify;
        }
        else
        {
            return "";//Test String contain 1 or more invalid chars
        }

    }

Update

SO Sorry to forget to meniton the spaces are allowd . thar was not a password field but a f.name + l.name collection having spaces also

"אב גד הו"

Was it helpful?

Solution

That is fine. To explain why the second value fails is because it has an apostrophe character ' . Same with the succeeding strings. They have either ', -, ., '' (2 single apostrophes)

To fix this, you just have to add the allowable characters in your check.

bool ISheb = StrToVerify.All(c => (c >= 0x0580 && c <= 0x05ff)
            || c == '.' //add this
            || c == '-' //add this
            || c == '\'' //add this
            || c == ' '); //add this
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top