| |

VerySource

 Forgot password?
 Register
Search
View: 755|Reply: 2

Questions about how the validation control validates Chinese and full-width?

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-17 12:00:01
| Show all posts |Read mode
I found that some of the validation controls on the form in the webpage are only valid for half-width validation. For example, the username is a RE control. I used w {4,16} for regular expression validation. As a result, the username was okay. When I input Chinese characters in my username, no matter how many errors are reported, and for example, when verifying the value of Email and numeric SingelText, inputting full-width numbers or alphabetic characters is verified. But is there a way to solve this problem? Or no matter what he typed, I changed to half-width characters when I verified? I don't know what to do, expert guidance.
Reply

Use magic Report

0

Threads

73

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-1-22 18:36:02
| Show all posts
/ [\u0000-\u00FF] / half-width symbol

/ [\u4E00-\u9FA5] / Chinese characters
 
/ [\uFF00-\uFFFF] / Full-width symbol

Use regular verification
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-22 17:00:01
| Show all posts
/// <summary>
/// Half-width to full-width
/// </summary>
/// <param name="BJstr"></param>
/// <returns></returns>
static public string GetQuanJiao(string BJstr)
{
#region
char[] c = BJstr.ToCharArray();
for (int i = 0; i <c.Length; i++)
{
byte[] b = System.Text.Encoding.Unicode.GetBytes(c, i, 1);
if (b.Length == 2)
{
if (b[1] == 0)
{
b[0] = (byte)(b[0]-32);
b[1] = 255;
c[i] = System.Text.Encoding.Unicode.GetChars(b)[0];
}
}
}

string strNew = new string(c);
return strNew;

#endregion
}

/// <summary>
/// Full angle to half angle
/// </summary>
/// <param name="QJstr"></param>
/// <returns></returns>
static public string GetBanJiao(string QJstr)
{
#region
char[] c = QJstr.ToCharArray();
for (int i = 0; i <c.Length; i++)
{
byte[] b = System.Text.Encoding.Unicode.GetBytes(c, i, 1);
if (b.Length == 2)
{
if (b[1] == 255)
{
b[0] = (byte)(b[0] + 32);
b[1] = 0;
c[i] = System.Text.Encoding.Unicode.GetChars(b)[0];
}
}
}
string strNew = new string(c);
return strNew;
#endregion
}
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list