`

<转>Using regex to validate email address

    博客分类:
  • ABAP
 
阅读更多
REPORT ZADN_SAMPLE.

*----------------------------------------------------------------------*
* -> CLASS cl_regex_test DEFINITION
*----------------------------------------------------------------------*
CLASS cl_regex_test DEFINITION FINAL.

  PUBLIC SECTION.

    METHODS : check_email IMPORTING p_email TYPE string.

  PRIVATE SECTION.

    DATA: o_regex   TYPE REF TO cl_abap_regex,
          o_matcher TYPE REF TO cl_abap_matcher.

ENDCLASS.                    "cl_regex_test DEFINITION

*----------------------------------------------------------------------*
* -> CLASS cl_regex_test IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS cl_regex_test IMPLEMENTATION.

  METHOD check_email.

* Create the regular expression:

    CREATE OBJECT o_regex
      EXPORTING
        pattern = '^[a-zA-Z]+(([\''\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*\s+<' &
                  '(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,3})>$|^(\w[-._\w]*' &
                  '\w@\w[-._\w]*\w\.\w{2,3})$'.

* Check to see if the email matches the regular expression:

    CREATE OBJECT o_matcher
      EXPORTING
        regex = o_regex
        text  = p_email.

    IF o_matcher->match( ) NE abap_true.

      MESSAGE 'Enter email address valid...' TYPE 'E'.

    ELSE.

      MESSAGE 'This is a valid email address...' TYPE 'S'.

    ENDIF.

  ENDMETHOD.                    "check_email

ENDCLASS.                    "cl_regex_test IMPLEMENTATION

************************************************************************
************************************************************************
*                                                                      *
*                           PROGRAM FLOW LOGIC                         *
*                                                                      *
************************************************************************

START-OF-SELECTION.

  DATA : ocl_regex_test TYPE REF TO cl_regex_test.

  CREATE OBJECT ocl_regex_test.

  ocl_regex_test->check_email( 'abapdn.network@mail.com' ).
分享到:
评论

相关推荐

    获取网页表格数据 正则表达式

    本文将详细探讨如何利用正则表达式来提取`&lt;tr&gt;`和`&lt;td&gt;`标签内的数据。 **正则表达式基础** 正则表达式是一种模式匹配工具,用于在文本中查找、替换或提取特定的字符串模式。在HTML中,`&lt;tr&gt;`标签定义了一行,`&lt;td&gt;...

    Beyond the C++ Standard Library An Introduction to Boost

    practice solutions for performing type conversions and lexical ...Regex&lt;br&gt;&lt;br&gt;Function objects defined at the call site with Boost.Bind and Boost.Lambda&lt;br&gt;&lt;br&gt;More flexible callbacks with Boost....

    对DAO编写单元测试源代码

    &lt;br&gt;&lt;br&gt;public class UserDaoImpl implements UserDao {&lt;br&gt;&lt;br&gt; public User queryForSignOn(String username) {&lt;br&gt; User user = queryUser(username);&lt;br&gt; if(user.getLocked())&lt;br&gt; throw new LockException...

    Beyond.the.C++ - Standard.Library.An.Introduction.to.Boost

    practice solutions for performing type conversions and lexical ...Regex&lt;br&gt;&lt;br&gt;Function objects defined at the call site with Boost.Bind and Boost.Lambda&lt;br&gt;&lt;br&gt;More flexible callbacks with Boost....

    The Java Developers Almanac

    &lt;br&gt;java.util.regex [26 examples] &lt;br&gt;java.util.zip [9 examples] &lt;br&gt;javax.accessibility [7 examples] &lt;br&gt;javax.crypto [14 examples] &lt;br&gt;javax.imageio [6 examples] &lt;br&gt;javax.naming [9 examples] &lt;br&gt;...

    EditPlus v2.31 fixpack

    This is a patch file to fix the bugs of EditPlus v2.31&lt;br&gt;&lt;br&gt;Copyright © 1998-2007 ES-Computing&lt;br&gt;Contact: support@editplus.com&lt;br&gt;Homepage: http://www.editplus.com/&lt;br&gt;&lt;br&gt;INSTALLATION&lt;br&gt;========...

    MFC应用程序在.NET框架下的扩展(2-1)

    32&lt;br&gt;2.1 引言 32&lt;br&gt;2.2 使用Regex类来分解字符串 32&lt;br&gt;2.3 用Match和MatchCollection类来搜索字符串 39&lt;br&gt;2.4 处理捕获组和捕获 45&lt;br&gt;2.5 解析和置换字符串 53&lt;br&gt;2.6 使用捕获组和替换模式置换匹配 56&lt;br&gt;2.7...

    nutch2.3.1安装文档教程

    &lt;value&gt;protocol-httpclient|urlfilter-regex|index-(basic|more)|query-(basic|site|url|lang)|indexer-solr|nutch-extensionpoints|protocol-httpclient|urlfilter-regex|parse-(text|html|msexcel|msword|...

    Mastering Regular Expressions, 3rd Edition

    书名:Mastering Regular Expressions, 3rd Edition&lt;br&gt;格式:CHM&lt;br&gt;语言:English&lt;br&gt;简介... If you think you know all you need to know about regular&lt;br&gt;expressions, this book is a stunning eye-opener.&lt;br&gt;

    正则取html中table中td中的值

    &lt;tr&gt;&lt;td&gt;数据1&lt;/td&gt;&lt;td&gt;数据2&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;数据3&lt;/td&gt;&lt;td&gt;数据4&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt; "; // 正则表达式匹配&lt;td&gt;中的内容 string pattern = @"&lt;td&gt;(.*?)&lt;\/td&gt;"; Regex regex = new Regex(pattern, ...

    Lucene查询工具LQT.zip

    --regex &lt;arg&gt; filter query by regex, syntax is field:/regex/ --show-hits show total hit count --show-id show Lucene document id in results --show-score show score in results --sort-fields sort ...

    android P 9.0添加Ethernet功能(settings+framework).zip

    &lt;br&gt;res\xml\network_and_internet.xml res\drawable\ic_ethernet_cell.xml &lt;br&gt;res\values\strings.xml res\xml\ethernet_settings.xml &lt;br&gt;res\xml\ethernet_static_ip.xml &lt;br&gt;src\...

    C++ 头文件大全

    - `&lt;regex&gt;`:正则表达式支持。 - `&lt;thread&gt;`:多线程支持。 - `&lt;atomic&gt;`:原子操作,用于线程安全。 - `&lt;mutex&gt;` 和 `&lt;condition_variable&gt;`:互斥锁和条件变量。 - `&lt;shared_ptr&gt;`,`&lt;unique_ptr&gt;` 和 `...

    C++头文件一览(Word格式)

    - `&lt;regex&gt;`:提供了正则表达式支持。 - `&lt;thread&gt;`:多线程支持,包括`std::thread`类。 - `&lt;mutex&gt;`和`&lt;atomic&gt;`:线程同步和原子操作。 - `&lt;chrono&gt;`:时间点和持续时间的处理,替代了`&lt;ctime&gt;`。 6. **...

    C语言头文件介绍大全

    * &lt;regex.h&gt;:正则表达式 * &lt;tar.h&gt;:tar归档值 * &lt;termios.h&gt;:终端I/O * &lt;unistd.h&gt;:符号常量 * &lt;utime.h&gt;:文件时间 * &lt;wordexp.h&gt;:字扩展类型 POSIX标准定义的XSI扩展头文件 POSIX标准定义了26个XSI扩展...

    db2-正则表达式.zip

    1- Save attached db2_regex.zip file to a... \&gt;db2 connect to &lt;my_db&gt; user &lt;uid&gt; using &lt;pwd&gt; \&gt;db2 set current schema='REGEXP' \&gt;db2 -td@ -vf C:\avalanche\db2_regex\scripts\sql\db2_regex_functions.sql

    asp正则表达式各种过滤函数.pdf

    regEx.Pattern = "&lt;(\/){0,1}object[^&lt;&gt;]*&gt;" regEx.IgnoreCase = True regEx.Global = True ClsTempLoseStr = regEx.Replace(ClsTempLoseStr,"") LoseObjectTag = ClsTempLoseStr Set regEx = Nothing End Function ...

    reg:具有 JS 正则表达式语法的最小 sed 类工具

    reg &lt;flags&gt; &lt;regex&gt; &lt;replacement&gt; 这直接映射到 Javascript 的String.replace函数: var regex = new RegExp ( &lt; regex&gt; , &lt; flags&gt; ); str.replace(regex, &lt; replacement&gt; ); 例子 cat /etc/passwd | reg :. *...

    C++ 提供了 头文件,其中包含了正则表达式的相关类和函数

    正则表达式

Global site tag (gtag.js) - Google Analytics