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