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 3271242
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:42:37+00:00 2026-05-17T18:42:37+00:00

Assume we want to validate user input, while user is typing in a JTextField.

  • 0

Assume we want to validate user input, while user is typing in a JTextField. For validating the user input, I wonder if I could use Ragel.

Assume the input should follow this example regex:

[a-z]{2,5}ABC[0-9]+

How can I do this with ragel? Can anybody give a short example how to validate user input “on the fly” (while inputing) with ragel?

The Ragel documentations misses some good examples for a Quick Start, so I ask here.

  • 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-05-17T18:42:38+00:00Added an answer on May 17, 2026 at 6:42 pm

    You can use EOF actions (section 3.2.2 EOF Actions in the Ragel documentation) for checking of the expressions on the fly with Ragel. They are triggered when end of input buffer is detected in a valid state (including non-final).

    Simple example:

      main := ([a-z]{2,5}'ABC'[0-9]+) @/{correct = 1;} %{correct = 1;};
    

    Action “@/” is for all non-final states. It includes starting state so empty string is correct for this case. Action “%” is for final state when entire input buffer matches the pattern. In the example above code for both actions are the same, but final state is often to be processed separately in practice. If it is not needed then the sample above can be simplified:

      main := ([a-z]{2,5}'ABC'[0-9]+) $/{correct = 1;};
    

    The complete Ragel sample with C output for checking the provided pattern is below. I hope that it is not a problem to convert it to Java.

      #include <stdio.h>
    
      %%{
       machine checker;
       write data;
      }%%
    
      unsigned char checker( const char *str )
      {
       /* standart Ragel variables */
       const char *p = str, *pe = str + strlen( str ) - 1; //-1 to strip "\n"
       const char *eof = pe;
       int cs;
    
       unsigned char correct = 0;
    
       %%{
        action final { printf("entire match"); correct = 1; }
        action partial { printf("partial match"); correct = 1; }
    
        main := ([a-z]{2,5}'ABC'[0-9]+) @/partial %final;
    
        write init;
        write exec;
       }%%
    
       return correct;
      };
    
    
      #define BUFSIZE 1024
      int main()
      {
       char buf[BUFSIZE];
       while ( fgets( buf, sizeof(buf), stdin ) != 0 ) {
        printf( "%d\n", checker( buf ));
       }
       return 0;
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement search functionality for a website (assume it is similar to
Assume a table structure of MyTable(KEY, datafield1, datafield2...) . Often I want to either
Assume that we have N erlang nodes, running same application. I want to share
Let's assume I'm a complete lazy bum and I don't want to invest the
Assume I have a class foo, and wish to use a std::map to store
Here is my custom module using hook, Assume if I want to pass argument
Assume i want to create 500 wxWidget like (some panels , color buttons and
Assume I want to program a Star Field animation. Not by using OpenGL but
Assume java 1.6 and leopard. Ideally, it would also be nice to get a
(assume php5) consider <?php $foo = 'some words'; //case 1 print these are $foo;

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.