From 7caf01d6717044b88e33eae0d63d6e70899b4a7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivo=20Pisa=C5=99ovic?= Date: Fri, 22 Jan 2016 12:17:45 +0100 Subject: [PATCH] The whole string needs to match number format. The original version also allowed values like "a21", "4b" or "7.2.5". --- SwiftValidator/Rules/FloatRule.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SwiftValidator/Rules/FloatRule.swift b/SwiftValidator/Rules/FloatRule.swift index f2b84fe..117d0af 100644 --- a/SwiftValidator/Rules/FloatRule.swift +++ b/SwiftValidator/Rules/FloatRule.swift @@ -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 } -} \ No newline at end of file +}