Implement serverside and client side validatation
This commit is contained in:
@@ -18,7 +18,7 @@ feature {NONE}
|
||||
|
||||
make_decimal_validator (e: STRING)
|
||||
do
|
||||
make_regexp_validator ("[0-9]+(\\.[0-9]*)?|\\.[0-9]+", e)
|
||||
make_regexp_validator ("^[0-9]+(\.[0-9]*)?$|^\.[0-9]+$", e)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -14,7 +14,7 @@ inherit
|
||||
create
|
||||
make_email_validator
|
||||
|
||||
feature{NONE}
|
||||
feature {NONE}
|
||||
|
||||
make_email_validator (e: STRING)
|
||||
do
|
||||
|
||||
@@ -10,6 +10,9 @@ class
|
||||
inherit
|
||||
|
||||
WSF_VALIDATOR [STRING]
|
||||
redefine
|
||||
state
|
||||
end
|
||||
|
||||
create
|
||||
make_regexp_validator
|
||||
@@ -18,21 +21,32 @@ feature {NONE}
|
||||
|
||||
make_regexp_validator (r, e: STRING)
|
||||
do
|
||||
make(e)
|
||||
make (e)
|
||||
regexp_string := r
|
||||
create regexp
|
||||
regexp.compile (r)
|
||||
end
|
||||
|
||||
feature -- Implementation
|
||||
|
||||
validate (input: STRING): BOOLEAN
|
||||
is_valid (input: STRING): BOOLEAN
|
||||
do
|
||||
--Only compile when used
|
||||
if not regexp.is_compiled then
|
||||
regexp.compile (regexp_string)
|
||||
end
|
||||
Result := regexp.matches (input)
|
||||
end
|
||||
|
||||
feature
|
||||
|
||||
state: JSON_OBJECT
|
||||
do
|
||||
create Result.make
|
||||
Result.put (create {JSON_STRING}.make_json ("WSF_REGEXP_VALIDATOR"), create {JSON_STRING}.make_json ("name"))
|
||||
Result.put (create {JSON_STRING}.make_json (regexp_string), create {JSON_STRING}.make_json ("expression"))
|
||||
Result.put (create {JSON_STRING}.make_json (error), create {JSON_STRING}.make_json ("error"))
|
||||
end
|
||||
|
||||
regexp_string: STRING
|
||||
|
||||
regexp: REGULAR_EXPRESSION
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
note
|
||||
description: "Summary description for {WSF_VALIDATABLE}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
WSF_VALIDATABLE
|
||||
|
||||
feature
|
||||
|
||||
validate
|
||||
deferred
|
||||
end
|
||||
|
||||
is_valid: BOOLEAN
|
||||
deferred
|
||||
end
|
||||
|
||||
end
|
||||
@@ -16,7 +16,14 @@ feature {NONE}
|
||||
|
||||
feature
|
||||
|
||||
validate (input: G): BOOLEAN
|
||||
state: JSON_OBJECT
|
||||
do
|
||||
create Result.make
|
||||
Result.put (create {JSON_STRING}.make_json (generator), create {JSON_STRING}.make_json ("name"))
|
||||
Result.put (create {JSON_STRING}.make_json (error), create {JSON_STRING}.make_json ("error"))
|
||||
end
|
||||
|
||||
is_valid (input: G): BOOLEAN
|
||||
deferred
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user