LoginSignup
11
4

More than 3 years have passed since last update.

Swiftで半角英数字を判定する

Posted at

Swiftで半角英数字を判定する

現在のSwift5ですぐに使える判定が意外と見つからなかったので。

String+.swift
    /// 文字が半角英数字のみか判定します
    /// - Returns: true:半角英数字のみ、false:半角英数字以外が含まれる
    func isAlphanumeric() -> Bool {
      return !isEmpty && range(of: "[^a-zA-Z0-9]", options: .regularExpression) == nil
    }

11
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
4