Unity3d 5 Inputfield Illegal path file name character input filter

Source: Internet
Author: User

Reprint please keep the original link: http://blog.csdn.net/andyhebear/article/details/51361747

    void Start () {if (this. Button = = null) {this. Button = this.        Getcomponentinchildren<ui_buttonclick> (); } if (this. Inputtext = = null) {this. Inputtext = this.        Getcomponentinchildren<inputfield> (); } this.        Button.onclickevent + = button_onclickevent; This.        Inputtext.onvalidateinput = _onvalidateinput; This.    InputText.onEndEdit.AddListener (Input_onendedit); } char _onvalidateinput (string text, int charIndex, char addedchar) {if (!_isvalidchar (Addedchar)) retur    n ' + ';//return empty return Addedchar; }//Illegal character list private bool _isvalidchar (char Addedchar) {//char[] invalid1 =system.io.path.getinvalidfilenamec        HARs (); for (int i = 0; i < INVALID1. Length;        i++) {//if (invalid1[i] = = Addedchar) {//return false;        }//}//char[] Invalid2=system.io.path.getinvalidpathchars (); for (int i = 0; i < Invalid2. LenGth        i++) {//if (invalid2[i] = = Addedchar) {//return false; }//} for (int i = 0; i < invalidfilepathnamechars.length; i++) {if ((int) Addedchar) =            = (int) invalidfilepathnamechars[i]) {return false; }} for (int i = 0; i < invalidcustomchars.length; i++) {if (Addedchar = = invalidcustomchars[            I]) {return false;    }} return true; }///<summary>///illegal filename path character char value///Getinvalidfilenamechars (), Getinvalidpathchars ()//</summary > private static readonly byte[] Invalidfilepathnamechars = new byte[]{34,60,62,124,0,1,2,3,4,5,6,7,8,9,10,11,    12,13,14,15,16,17,18,19,20, 21,22,23,24,25,26,27,28,29,30,31,58,42,63,92,47}; <summary>///custom illegal characters///</summary> private static readonly char[] Invalidcustomchars = new Char []{        '\'','"','~','`','!','@','#','$','%', ' ^ ', ' & ', ' * ', ' (', ') ', ' + ', ' = ', ' > ', ' < ', ' | ', ' {', '} ', '/', ' \ \ ', ': ', '? ', ', ', '? '      }; <summary>///Determine if the Unicode value of the character is kanji///</summary>//<param name= "code" > Character Unicode</param >//<returns></returns> protected static bool Ischineseletter (int code) {int chfrom = Syste    M.convert.toint32 ("4e00", 16);        The range (0X4E00~0X9FFF) is converted to int (chfrom~chend) int chend = System.Convert.ToInt32 ("9fff", 16);     If (Code >= chfrom && Code <= chend) {return true;    When code returns true within the Chinese range} else {return false;    When code is not in the Chinese range, return false} return false;  }

Unity3d 5 Inputfield Illegal path file name character input filter

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.