반응형
유니티 C# 비속어 필터 적용 inputfield 간단 사용법
Assets / Resoures / BadWord.txt 준비
코드 작성
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.UI;
public class Example : MonoBehaviour
{
public InputField inputField;
public string[] lines;
string LINE_SPLIT_RE = @"\r\n|\n\r|\n|\r";
void Awake()
{
if (File.Exists(file))
{
StreamReader word = new StreamReader(file);
source = word.ReadToEnd();
word.Close();
lines = Regex.Split(source, LINE_SPLIT_RE);
}
}
public void ChangeNickName()
{
for (int i = 0; i < lines.Length; i++)
{
if (inputField.text.Contains(lines[i]))
{
Debug.Log("비속어는 사용할 수 없습니다.");
return;
}
}
string Check = Regex.Replace(inputField.text, @"[^a-zA-Z0-9가-힣 ]", "", RegexOptions.Singleline);
if (inputField.text.Equals(Check) == true)
{
Debug.Log("닉네임이 변경되었습니다.");
}
else
{
Debug.Log("특수문자는 사용할 수 없습니다.");
}
}
}
참고할만한 글
반응형
'개발 > C#' 카테고리의 다른 글
유니티 C# 로컬 푸시 알림 Local Push Notification 간단 구현 (0) | 2022.08.17 |
---|---|
유니티 C# 부모 자식 오브젝트 가져오기 GetChild 간단 사용법 (0) | 2022.08.17 |
유니티 C# 리소스 로드 Resource.Load 함수 간단 사용법 (0) | 2022.08.17 |
유니티 C# 애플 로그인 Sign ln with Apple Login 간단 구현 (0) | 2022.08.17 |
유니티 C# 디버그 로그 종류 Debug.Log 간단 사용법 (0) | 2022.07.13 |
유니티 C# 자주 사용하는 연산자 Operator 모음 (0) | 2022.07.13 |
유니티 C# 구글 스프레드 시트 Google Sheet 간단 사용법 (0) | 2022.07.13 |
유니티 C# 오디오 Audio Source , Audio Clip 간단 사용법 (0) | 2022.07.06 |
댓글