Asp.net c # and vb.net can only input English and digital functions

Source: Internet
Author: User
Tags chr

This article is also intended for asp tutorials. net is about asp.net tutorial c # and vb.net can only input English and digital functions, the first is c # limit can only input numbers and English, the last shows is vb.net, the principles are all one character, and then the internal code value is determined as follows.

C #

Private void textbox1_textchanged (object sender, eventargs e)
        {
Char [] clist = textbox1.text. tochararray ();
String newstr = "";
For (int I = 0; I <clist. length; I ++)
            {
Int ascii = (int) clist [I];
If (ascii> 127)
                {
Clist [I] = '';
                }
Newstr + = clist [I]. tostring ();
            }

Textbox1.text = newstr;
        }

Vb.net

 

Function valitext (keyin as integer, validatestring as string, editable as boolean) as integer
Dim validatelist as string
Dim keyout as integer
           
If editable = true then
Validatelist = ucase (validatestring) & chr (8)
Else
Validatelist = ucase (validatestring)
End if
           
If instr (1, validatelist, ucase (chr (keyin), 1)> 0 then
Keyout = keyin
Else
Keyout = 0
End if
Valitext = keyout
End function


Call method

Private sub txtmoney_keypress (keyascii as integer)
Keyascii = valitext (keyascii, "0123456789.", true)
End sub
   
Private sub txtid_keypress (keyascii as integer)
Keyascii = valitext (keyascii, "0123456789-abcdefghijklmnopqrstuvwxyz", true)
End sub

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.