如果searchView只包含数字,我该如何检查?
我找到了这个:
if newText.isMatchedByRegex("^(?:|0|[1-9]\\d*)(?:\\.\\d*)?$") { ... }
Run Code Online (Sandbox Code Playgroud)
但它检查文本是否包含任何数字.如果所有文本只包含Swift中的数字,我该怎么办?
Two*_*aws 33
这是您可以从中获取所有数字的解决方案String.
let testString = "asdfsdsds12345gdssdsasdf"
let phone = testString.components(separatedBy: CharacterSet.decimalDigits.inverted).joined(separator: "")
print(phone)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17829 次 |
| 最近记录: |