Halikal实际上已经解决了这个问题,但直到现在才分享......
这适用于 eiffelStudio 6.2(注意 - 这是图案片)
http://se.inf.ethz.ch/old/people/leitner/gobo_guidelines/naming_conventions.html
有效的电话号码包括以下之一:
- 八位数字,其中第一位非零
- 一个前导零,一个非零数字区号,然后是八位数字,其中第一个非零
- 前导 + 后跟两位国家代码,然后是单个非零数字地区代码,然后是八位数字,其中第一个是非零
验证电话号码时,将忽略任何嵌入的空格。
require -- 040 is ascii hex space
valid_phone:
match(phone, "^\040*[1-9]\040*([0-9]\040*){7}$") = TRUE or
match(phone, "^\040*0\040*([1-9]\040*){2}([0-9]\040*){7}$") = TRUE or
match(phone, "^\040*\+\040*([0-9]\040*){2}([1-9]\040*){2}([0-9]\040*){7}$") = TRUE
feature --Regular Expression check
match(text: STRING; pattern: STRING): BOOLEAN is
-- checks whether 'text' matches a regular expression 'pattern'
require
text /= Void
pattern /= Void
local
dfa: LX_DFA_REGULAR_EXPRESSION --There's the Trick!
do
create dfa.make
dfa.compile(pattern, True) --There's the Trick!
check -- regex must be compiled before we can use it
dfa.is_compiled;
end
Result := dfa.matches(text)
-- debug: make sure of which pattern
if dfa.matches (text) then
io.putstring(text + " matches " + pattern + "%N")
end
end
end