Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8528695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:51:37+00:00 2026-06-11T08:51:37+00:00

I have an input field which should accept only letters (doesn’t matter lower or

  • 0

I have an input field which should accept only letters (doesn’t matter lower or uppercase).
I could write this simply by using co ca (contains only/any) operator. But it’s time consuming.

  if p_input3 ca '*/ + - ? ! % ( ) = 0123456789'.
    MESSAGE e000 WITH 'Only letters are allowed. No numbers or special characters'.
  ENDIF.

It works. But I wanted to check it using regex.
I tried this code. But It doesn’t work quite well.

DATA: text TYPE string,
      matcher type REF TO cl_abap_matcher.

PARAMETERS: p_input3 TYPE string DEFAULT 'abCD*()fhi' LOWER CASE.

matcher = cl_abap_matcher=>create(
   pattern = `([a-zA-Z])`
    text = p_input3
  ).

  if matcher = abap_true.
    MESSAGE e000 with 'Only letters are allowed. No numbers or special characters'.
  ENDIF.

Could anyone figure it out?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T08:51:38+00:00Added an answer on June 11, 2026 at 8:51 am

    First, your regular expression won’t work. It is only successful when your input contains only a single letter.

    This one will work correctly:

    '[a-zA-Z]*'
    

    + and * mean repetition. That means a chain of any number of characters which falls into the preceding category. The difference is that * can also mean 0 times, while + means at least one time. So an empty string would match [a-z]* but not [a-z]+

    Then you are checking the reference to the matcher object itself for being equal to abap_true. This won’t ever happen, because it will always be a reference to a matcher object, not abap_true or abap_false.

    To get the result of a match, you have to not just create the matcher but actually run it by calling its match method.

    IF matcher->match( ) = abap_false.
        MESSAGE e000 with 'Only letters are allowed. No numbers or special characters'.      
    ENDIF. 
    

    But there is also a much easier way to do this with the FIND REGEX command instead of the class cl_abap_matcher:

    FIND FIRST OCCURRENCE OF REGEX '[^a-zA-Z]' IN p_input3.
    IF sy-subrc = 0.
        MESSAGE 'There is some non-letter in your input.' TYPE 'E'.
    ENDIF.
    

    ^ means negation. So [^a-zA-Z] means any character which is NOT in the given range.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a field which should take input in format HH:MM (it can be
I have two regular expressions for one user input field that should accept a
I have a Javascript function which should update a hidden input field in my
I have an input field which has a placeholder text. I want one word
i have an input field which will be displayed. i want that to hide
I have an input text field which has style: visibility: visible or style: visibility:
I have a form with input field which can be accessed like var algorithm
I have created a add input field function which is working fine. I would
I have an input text field, which has a value something by default, but
Dear community members, I have a small problem, which involves a text input field

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.