Help us understand the problem. What is going on with this article?

【Obj-C】TextFieldやTextViewで入力された文字に「特殊文字、機種依存文字」などが含まれているかどうかを判定したい

More than 3 years have passed since last update.

概要

ユーザーに任意の文字を入力させ、その入力情報をサーバーに送る際、サーバー側の都合もあり、Shift_JISで対応できない特殊文字を排除する処理(バリデーション)をフロント側で行うことになったので、その時の対応メモ

対応方法

入力された文字列をShift_JISに変換できるかを判定する関数「canBeConvertedToEncoding:NSShiftJISStringEncoding」を利用して、返り値のBOOLで判定した。

コード

BOOL returnBool = [textview.text canBeConvertedToEncoding:NSShiftJISStringEncoding];
if(returnBool){
 //入力文字に特殊文字が含まれていない時の処理
}else{
 //入力文字に特殊文字が含まれている時の処理
}

何かご指摘やもっと良い方法等がありましたらコメントお願いします!

asa_s
Unity Engineer (2016 - now), Scala Engineer (2016 - now), iOS Engineer (2014 - 2016)
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした