The whole string needs to match number format.
The original version also allowed values like "a21", "4b" or "7.2.5".
This commit is contained in:
parent
5f0f429df8
commit
7caf01d671
|
|
@ -17,7 +17,7 @@ public class FloatRule:Rule {
|
|||
}
|
||||
|
||||
public func validate(value: String) -> Bool {
|
||||
let regex = try? NSRegularExpression(pattern: "[-+]?(\\d*[.])?\\d+", options: [])
|
||||
let regex = try? NSRegularExpression(pattern: "^[-+]?(\\d*[.])?\\d+$", options: [])
|
||||
if let regex = regex {
|
||||
let match = regex.numberOfMatchesInString(value, options: [], range: NSRange(location: 0, length: value.characters.count))
|
||||
return match == 1
|
||||
|
|
@ -28,4 +28,4 @@ public class FloatRule:Rule {
|
|||
public func errorMessage() -> String {
|
||||
return message
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue