unity3d 5 InputField 非法路径文件名字符 输入过滤
转载请保留原文链接: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)) return '\0';//返回空return addedChar;} //非法字符列表private bool _isValidChar(char addedChar) {//char[] invalid1 =System.IO.Path.GetInvalidFileNameChars();//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>/// 非法文件名路径 字符char值/// 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>/// 自定义非法字符/// </summary>private static readonly char[] InvalidCustomChars = new char[]{'\'','"','~','`','!','@','#','$','%','^','&','*','(',')','+','=','>','<','|','{','}','/','\\',':',';',',','?' };/// <summary>/// 判断字符的Unicode值是否是汉字/// </summary>/// <param name="code">字符的Unicode</param>/// <returns></returns>protected static bool IsChineseLetter(int code) {int chfrom = System.Convert.ToInt32("4e00", 16); //范围(0x4e00~0x9fff)转换成int(chfrom~chend)int chend = System.Convert.ToInt32("9fff", 16);if (code >= chfrom && code <= chend) {return true; //当code在中文范围内返回true}else {return false; //当code不在中文范围内返回false}return false;}
unity3d 5 InputField 非法路径文件名字符 输入过滤相关推荐
- window、linux、mac 文件路径禁止字符, 路径长度【全网总结】
参考: https://9to5answer.com/what-characters-are-forbidden-in-windows-and-linux-directory-names https: ...
- bat - 批量替换文件名字符
批量替换文件名字符 @echo off & setlocal enableDelayedExpansion rem 1 这是提示输入文件位置,直接打开文件夹复制路径.黏贴就行 set /p p ...
- 将文件名发送到服务器,将Paperclip路径文件名从服务器更新到s3(Updating Paperclip path file names from on server to s3)...
将Paperclip路径文件名从服务器更新到s3(Updating Paperclip path file names from on server to s3) 我有一个回形针实例,我将我的文件迁移 ...
- php过滤非法字符函数,利用php怎么对非法字符进行过滤
利用php怎么对非法字符进行过滤 发布时间:2020-12-28 16:41:22 来源:亿速云 阅读:94 作者:Leah 这篇文章将为大家详细讲解有关利用php怎么对非法字符进行过滤,文章内容质量 ...
- vba不能提取服务器上文件名,从全路径文件名中获取文件名(不含路径)
从全路径文件名中获取文件名(不含路径) 方法一: Public Function gf_GetFileName(strFullPath As String) As String Dim splitLi ...
- AutoCAD打开报错,致命错误:无效的配置路径/文件名
运行AutoCAD时,无法打开并显示以下消息: AutoCAD错误中止 致命错误:无效的配置路径\文件名: 解决方法: 将C:\Users\username\AppData\Roaming目录下的A ...
- html提交提示非法字符串,教你如何过滤高亮显示非法字符
本篇教你如何过滤高亮显示非法字符: //我只是做一个测试,如果再用类似tmd的字符串,一定要注意,如果字符串中的字符出现在$StartReplaceHtml或者$EndReplaceHtml中,你需要 ...
- 有关 Thumbnails的报错No suitable ImageReader found for 文件路径/文件名.jpg
使用 Thumbnails进行图片压缩时报错: No suitable ImageReader found for 文件路径/文件名.jpg 初始代码: Thumbnails.of(address). ...
- mysql 危险字符_PHP过滤指定字符串,过滤危险字符
安全过滤函数,用于过滤危险字符 function safe_replace($string) { $string = str_replace(' ','',$string); $string = st ...
最新文章
- linux从源码编译软件,linux软件包管理——源码包编译安装
- 网页与APP中那些优美的登陆表单
- java怎么输入数据_java怎么键盘输入数据啊?
- if else if语句格式_闲话Python之条件语句IF
- 面试题——死锁的实现
- Vista SP1吞吃硬盘 将给我们带来哪些影响
- mac apache修改默认网站目录
- BGP十三条选路原则
- 【Windows网络编程】完成端口IOCP介绍(超详细)
- 疫情影响下普惠金融风险与对策
- 形容等待时间长的句子_形容等待已久的事终于等到句子
- 队列基本操作模拟打印机任务管理
- 浅谈知识表示之语义网络、RDF和OWL
- 王传福的梦想,不止7000亿
- 构建知识体系(1):知识体系是什么?
- vue3 使用富文本tinymce-vue
- matlab win32错误,尝试运行Matlab-Compiler-Runtime应用程序时Windows 7中出现SxS错误
- 西电计算机绘图试题及答案,【图】- 西安电子科技大学2021春 计算机绘图(大作业)答 - 苏州常熟常熟周边其他教育培训 - 苏州百姓网...
- ELK之JStorm
- 笔记本安装Win2012R2 心得(包含无线网卡+有线网卡驱动解决方法)