Regular Expression Validator Problem

Hi,
I have a text area that I want to use a regular expression
validator on to verify that one or more 9 char alphanumeric serial
numbers were entered.
<mx:RegExpValidator
source="{entryField}"
property="text"
flags="gi"
expression="{/[a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0- 9][a-zA-Z0-9][a-zA-Z0-9](
|,|\\n|\\r|\\t)/}"
valid="handleResult(event)"
invalid="handleResult(event)"
trigger="{entryField}"
triggerEvent="textInput"
/>
//for testing
private function
handleResult(eventObj:ValidationResultEvent):void {
if (eventObj.type == ValidationResultEvent.VALID)
entryField.setStyle("borderColor", "green");
entryField.setStyle("borderThickness", "2");
else
entryField.setStyle("borderColor", "red");
entryField.setStyle("borderThickness", "2");
The problem is the handler function always comes back
invalid, even when it should be valid, such as: 123456789 a12345678
lk231jkop
Can anyone advise where I might be going wrong?
Thanks!

This is weird, i just tried your RegExp using the Adobe's
Live Docs example and it worked perfectly.
Try it at:
http://livedocs.adobe.com/flex/201/langref/mx/validators/RegExpValidator.html
Scroll down to the end of the page, then type your RegExp and
your TestValue and click the Validate button, it works. I am
guessing that maybe it is your
i
flag, try removing it from your validator.
Hope this helps

Similar Messages

  • Inline display of error message for a regular expression validation

    Hi All,
    I am using ApexLib in my application.
    I am using regular expression validation for some of the items.
    Those validation will happen when the button is pressed and the message will be displayed as per the error.
    But, I want the errors to be displayed immediately when the focus is away from that item.
    as we do for required items.
    could anybody help me to achieve it?
    Thanks in advance
    bye
    Srikavi

    Hi Srikavi,
    to achieve a Validation of an item when leaving the field you'll have to use some javascript code (as ApexLib does internally).
    What do you need:
    - onChange - Event on your Item
    - some Javascript code which is called in the onChange Event (you can put this code either in your page html header or, if it is used more often in your application, in a seperate js File)
    - call the ApexLib method apexlib.error.showError to display your error
    I actually never tried it myself, but i'm pretty sure that this will work (according to what i've seen in the ApexLib code).
    Have fun and tell us how it went,
    Peter
    Edited by: peter_raganitsch on Sep 5, 2008 11:56 AM

  • Reset Item After Regular Expression Validation Fails

    Apex 4.2
    I have a page item (P1_MYITEM) that should only hold alpha charaters, so I have created an item regular expression validation
    using
    ^[a-zA-Z]+$
    This works well, but now I want to reset my item (P1_MYITEM) to null
    if the validation fails.
    Tried using a page process, but they do not run if the validation fails.
    Any ideas ?
    Gus

    Got it working using
    Begin
      if not regexp_like (:P1_MYITEM, '^[a-zA-Z]+$')
        then
          APEX_UTIL.SET_SESSION_STATE('P1_MYITEM',NULL);
          return 'Country must be text characters only.';
      end if;
    End;

  • Regular Expression Validator - want to edit an object acct field

    The field is a character field. But the field must be editted as follows:
    Field must either be 4 numeric numbers with the first position always an 8 so it could be a range from 8000 to 8999
    But I must also allow them to enter "8%" or "8n%" or "8nn%" where n represents a number. They want me to allow wild cards.
    How would I define this edit on the same field.
    1) First Validation: If it has a "%" then the first digit must be an 8 then I can have any of the wild card combinations given above.
    2) Second Validation: If no wild card then the field must be in the range from 8000-8999
    Is this validation a candidate for Regular Expression Validator or for my own custom method.
    If I can code this as a regular expression validator how would I code it. I spent the last day looking on the web for Regular Expression Validator examples.

    I get the following errors that occur. I can key 8% or 8ddd but when I try these combinations 8d% or 8dd% then the following errors pop up. It gives multiple error but I am just keying on a single line. I can add multiple object lines but just one at a time.
    java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    - JBO-ObjectCode_Rule_1: Object must be in range 8000-8999 or object must be in form of 8%, 8n%, 8nn% where n represents a number.
    - JBO-27008: Attribute set for ObjectCode in view object AccountsecuritygroupobjView2 failed
    - JBO-ObjectCode_Rule_1: Object must be in range 8000-8999 or object must be in form of 8%, 8n%, 8nn% where n represents a number.
    - JBO-ObjectCode_Rule_1: Object must be in range 8000-8999 or object must be in form of 8%, 8n%, 8nn% where n represents a number.
    - JBO-27008: Attribute set for ObjectCode in view object AccountsecuritygroupobjView2 failed
    - JBO-ObjectCode_Rule_1: Object must be in range 8000-8999 or object must be in form of 8%, 8n%, 8nn% where n represents a number.

  • Regular Expression Validation

    Hi,
    I'm trying to use a regular expression to validate password.
    I create a validation in my item called P502_PASSWORD. I choose regular expression type. At the Validation Expression 2, I put this expression:
    ^(?=.*\d)(?=.*[a-zA-Z])(?!.*[\W_\x7B-\xFF]).{6,15}$
    So, I tried to enter a valid "string" at this item. For example: abc123
    But it doesn't work and I don't know why. I have another item with a e-mail validation with the expression below, and works:
    ^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$
    So, i really don't know what is happening.
    Can someone help me? :)
    Thanks,
    Vivi

    Hi Vivi,
    I checked your regex with my favourite application and it seems to be correct for a 'liberal' interpreter. But POSIX-implementation in Oracle seems to be quite strict. At least, I get an ORA-12728 ("invalid range in regular expression") when executing your string with "REGEXP_LIKE". I would take the regex apart bit by bit and see when the regex starts to work with REGEXP_LIKE, like in the following example:
    BEGIN
      dbms_output.put_line(case when regexp_like('aBc123','^(((\d)|([[:alpha:]])){6,15})$') then 'hit' else 'miss' end);
    END;
    /This is of course not exactly the expression you wanted, but I guess it's not very far away and produces a 'hit'. ;)
    If anybody finds out what exactly caused the error I'd like to know. My first guess was the asterisk in combination with {6,15}, but just removing it didn't do the trick.
    -Udo

  • Regular Expression escaping problem!

    Hi all,
    Well as you know characters such as '*' and '?' are reserved characters in regular expression so I suppose if I want to find the exact character (a '?' for example) in a string, I have to escape it with a backslash:
    str=str.replaceAll("\?","a");
    In the statement above, I need to replace all question marks with another character but it has a compile error:
    Error(116,48): invalid escape character
    to my surprise this following code does the job while it should be interpreted as: one occurance of the '\' character or nothing at all:
    str=str.replaceAll("\\?","a");
    What's the problem? what's the general rule on escaping such characters?

    I think you're right.
    The point is that java first interprets the String and handle its own scape characters then the result would be passed on to reqular expression parser.
    so I guess in order to search for one occurance of the '\' character or nothing at all the java string would be:
    so that the input to reqular expression parser would be:
    while in the first situation:
    a "\\?" java string is first trasformed into \? which will be considerd as one occurance '?' in reqular expression point of view...
    Message was edited by:
    nerssi
    Message was edited by:
    nerssi

  • Regular Expression compilation problem

    I am trying to use JDK 1.4's regular expression classes to match text that appears with curly braces (e.g. {field1}) using the following regular expression:
    [{]([0-9A-Za-z]+)[}]
    I use this same pattern with the org.apache.regexp and org.apache.oro packages without any problem, but get the following error when running it using the new java.util.regex package in JDK 1.4:
    Exception in thread "main" java.util.regex.PatternSyntaxException: Unexpected character '?' near index 0
    [{]([0-9A-Za-z]+)[}]
    ^
    at java.util.regex.Pattern.error(Pattern.java:1472)
    at java.util.regex.Pattern.range(Pattern.java:2052)
    at java.util.regex.Pattern.clazz(Pattern.java:1991)
    at java.util.regex.Pattern.sequence(Pattern.java:1529)
    at java.util.regex.Pattern.expr(Pattern.java:1489)
    at java.util.regex.Pattern.compile(Pattern.java:1257)
    at java.util.regex.Pattern.<init>(Pattern.java:1013)
    at java.util.regex.Pattern.compile(Pattern.java:760)
    at Test_jdk14.main(Test_jdk14.java:13)
    What am I doing wrong?
    Thanks, Tony

    Hello,
    Let's look at what you've done.
    [\\{]([0-9A-Za-z]+)[}]Okay, first you escape the opening curly brace, but you did not escape the closing curly brace.
    [\\{]([0-9A-Za-z]+)[\\}]Next, you use the square brackets, but you only have one thing in the brackets, so, they are unnecessary:
    \\{([0-9A-Za-z]+)\\}Next, I am going to contract all that stuff inside your remaining square brackets to \\w, since that covers 0-9A-Za-z_
    \\{(\\w+)\\}Now, are you expecting any sort of spaces within the curly brackets? If so, you didn't specify them. I'll assume you didn't.
    Now you did all this, but it still doesn't match what you thought it would match. Did you use Matcher.matches or Matcher.lookingAt?
    If you look at the API for these methods, you'll see that
    a) Matcher.matches(...) only returns true if the entire input sequence matches the pattern.
    b) Matcher.lookingAt(...) only returns true if the start of the input sequence matches the pattern.
    In either of these cases, if your string didn't start with the opening bracket, then the Pattern (in its current form) won't match. For example:
    "{text1}"                       // matches() == true
                                    // lookingAt() == true
    "{text2} blah blah"             // matches() == false
                                    // lookingAt() == true
    "blah blah {text3}"             // matches() == false
                                    // lookingAt() == false
    "blah blah {text4} blah blah"   // matches() == false
                                    // lookingAt() == false
                                    //You would want to use Matcher.find() if you want to find all of these matches.
    However, there is a way to find those matches using Matcher.matches() and Matcher.lookingAt(). All you have to do is put .* in front and behind the thing you're looking for.
    .*\\{([\\w]+)\\}.*This way, any number of characters can come before or after your pattern, and it will still fit the requirements.
    Here's an example:
    import java.util.*;
    import java.util.regex.*;
    public class RegExample
       public static void main( String [] args )
          Pattern p = Pattern.compile( ".*\\{(\\w+)\\}.*" );
          Matcher m = p.matcher( "blah blah {field1} blah blah" );
          if ( m.lookingAt() )
             System.out.println( "We're looking at it." );
          if ( m.matches() )
             System.out.println( "It matches." );
          m.reset();
          if ( m.find() )
             System.out.println( "we found the first match" );
             System.out.println( "It was: " + m.group(1) );
    }

  • Tomahawk Regular expression Validator

    Hi,
    I am trying to use Tomahawk RegEx Validator in my application.
    My questions are as follows.
    1. I want to get the pattern of the regular expression from the bean or resource bundle. Is this possible?
    2. If I use the pattern as in <t:validateRegExpr pattern='[a-zA-Z\s]+'/> it works perfectly fine. But when I change that to <t:validateRegExpr pattern='\\p{N}+'/> it doesn't work. I want to do this as there won't be any issues with internationalsation.
    Please let me know how these issues can be addressed.
    Thanks in Advance.
    Regards,
    Raja

    manick_r wrote:
    1. I want to get the pattern of the regular expression from the bean or resource bundle. Is this possible?Read the TLD documentation of the tag in question. If the 'pattern' attribute accepts a ValueExpression, then it is possible. I can't directly answer this as you're at a Sun JSF forum, not at an Apache Tomahawk mailinglist.
    2. If I use the pattern as in <t:validateRegExpr pattern='[a-zA-Z\s]+'/> it works perfectly fine. But when I change that to <t:validateRegExpr pattern='\\p{N}+'/> it doesn't work. I want to do this as there won't be any issues with internationalsation.Please elaborate "it doesn't work". What did you expect it to do and what did it do unexpectedly instead? Does this pattern work when you just use it in String#matches()? Provide a SSCCE if you can.

  • Regular Expression Validator

    Are there plans to include a validator based on regular expressions in the first releae of JSF. I can imagine many consumers of JSF writing their own if one isn't provided out of the box. I know .NET has such a thing.

    I would also like to vote for such a thing.
    Does anyone know whether the JSF crew is reading these posts?
    I was really wondering why this validator is missing and I fear that it is missing because some JSF people don't want one, since otherwise having a regexp validator would be the most intuitive validator to have.
    Some frameworks combine regexp matching with internationalization and localization. This is one aspect that does not really have to be considered with the validators out so far. Maybe that is the reason for why the RegexpValidator is missing.
    Also, since JSF needs to be compatible to JDK1.3, there would have to be an extra regexp package like oro to be included within the faces implementation. And someone would have to write a validator using this package for jdk1.3 and another one using the jdk1.4 buildin regexp package. Maybe that's why there is not yet one available...

  • Regular Expression wierdness - problem with $ character

    If I use the following KM code in Beanshell Technology - it works correctly and replaces "C$_0MYREMOTETABLE RMTALIAS, MYLOCALTABLE LOCALIAS, " with "C$_0MYREMOTETABLE_000111 RMTALIAS, MYLOCALTABLE LOCALIAS, "
    But when I try to use the same exact code in 'Undefined' technology - it does not match anything in the source string - and does not replace anything.
    If I change the regular expression to not use the $ it still does not work.
    But if I change the source string to remove the $ - then the regular expression works.
    If I use the same code in Beanshell technology - it works fine - but then I can't use the value in a later 'Undefined' technology step.
    Does anyone know if the java technology does something special with $ characters when ODI parses the KM code?
    Does anyone know if there is a way to use the value from a Beanshell variable in a 'Undefined' technology step?
    String newSourceTableList = "";
    String sessionNum ="<%=odiRef.getSession("SESS_NO") %>";
    String sourceTableList = "<%=odiRef.getSrcTablesList("", "[WORK_SCHEMA].[TABLE_NAME] [POP_TAB_ALIAS]" , ",", ",") %>";
    String matchExpr = "(C\\$_\\S*)"; (should end with two backslashes followed by 'S*' - this editor mangles it)
    String replaceExpr = "$0_"+sessionNum+ " ";
    newSourceTableList = sourceTableList.replaceAll(matchExpr,replaceExpr);
    ---------------------------------------------------

    Phases of substitution in ODI:
    The way ODI works allows for three separate phases of substitution, and you can use them all. The three phases are:
    - First Phase: <% %> You will see these appear in the knowledge moduiles etc and these are substituted on generation. (when you generate a scenario, or tell ODI to execute an interface directly) this phase is used to generate the column names, table names etc which are known from the metadata at that phase.
    - Second Phase: <? ?> This phase is substituted when the scenario is instatntiuated as an excution - session generation. At this point, ODI has the additional information which allows it to generate the schema names, as it has resolved the Logical/Physical Schemas through the use of the Context (which is provided for the execution to take place. All the substitutions at this point are written to the execution log.
    - Third Phase <@ @> This phase is substituted when the execution code is read from the session log for execution. You will note that anything substituted in this phase is NEVER written to the execution log. (see PASSWORDS as a prime example, you don't want those written to the logs, with the security risks associated with that!)
    Anything in <@ @> is always interpreted for substitution by the java beanshell, it does not have to be a Java Beanshell step, it can be any kind of step, it will be interpreted at that run-time point.

  • Problem with  regular expression  validation

    hi,
       how can i validate folder structure
       conditions
         no two  forward slashes(/) in a sequence no  special characters
        " /w" and   "  '/'  "    
       e:/tomcat/ss/ss.text
           if(valStr.matches("((['/'])[a-zA-Z0-9_]*)")){
                    System.out.println("matches");   
             else
                    System.out.println("notmatches");
    this is no correct .
    please give me right solution       
    with regards
    ss

    hI,
      /appmg/dd/
    is  the paths for solaris( starts with /)
    i have to test  if it is valid path name or not
    with regards
    ss

  • Keystroke regular expression (regex) problem

    I have a text field that should only permit the following values: "V", "X" or "NA" (all uppercase).
    I'm fairly OK with javascript in pdf and I have a script that validates these when the field losses focus.
    What would be much better is to have a keystroke script that only permits these values to be entered. I've found elsewhere in the forums a useful starting point here:
    var re = /^[A-Za-z0-9 :\\_]$/;
    event.change = event.change.toUpperCase();
    if (event.change.length >0) {
    if (event.willCommit == false) {
        if (!re.test(event.change)) {
            event.rc = false
    but I've been unable to come up with anything for the regexp pattern that works reliably (these are definitely not my strong point).
    Grateful thanks for any help.

    You can apply the RegEX to the keystroke and restrict the keystroke values that be entered or you can use the validation tab to enter a script to restrict the input to specific values.
    The script you are using only checks the entered character so it will not test the string "NA" which is 2 characters.
    Another approach for such a limited number of input options would be a combo box  or drop down box where the options are space, "V", "X", and "NA". The value of the field would then be limited to a space (no selection made), a V, X, or NA.

  • Regular Expression Validation Puzzle

    Simple validation of a incomming contact name ..
    $contact_name = trim($_POST['contact_name']);
    if (!ereg("^([a-zA-Z \'-]+){5,10}$", $contact_name))
    { $errors [] = 'Enter valid contact name'; }
    As you can see the name must be u/l case alpha or space,
    apostophe or hyphen (I think that is all a name can be) and must be
    at least 5 chars and no more than 10 (just testing).
    The character validation seems ok and it picks up when there
    is less that 5 chars, but the max parameters doesn't seem to work
    at all - any ideas?
    PS. Is there a routine that strips out more than one space
    between words, e.g if someone entered 'John Smith', it would return
    'John Smith'?,
    Thanks.

    Hi David,
    I have tried this and I am still getting an unexpectred
    error:
    Joe O'Kane appears on my error message as invalid - Joe
    O\'Kane (11 Characters) whilst
    Joe O-Kane appears as valid Joe O-Kane (10 Chars)?
    I have tried both suggested scripts - my code is ...
    $errors = array();
    if (get_magic_quotes_gpc())
    { function undoMagicQuotes($array, $topLevel=true)
    { $newArray = array();
    foreach($array as $key => $value)
    { if (!$topLevel) { $key = stripslashes($key); }
    if (is_array($value)) {$newArray[$key] =
    undoMagicQuotes($value, false); }
    else { $newArray[$key] = stripslashes($value); }
    return $newArray;
    $_GET = undoMagicQuotes($_GET);
    $_POST = undoMagicQuotes($_POST);
    $_COOKIE = undoMagicQuotes($_COOKIE);
    $_REQUEST = undoMagicQuotes($_REQUEST);
    //if (get_magic_quotes_gpc())
    //{function stripslashes_deep($value)
    //{ $value = is_array($value) ?
    array_map('stripslashes_deep', $value) : stripslashes($value);
    //return $value; }
    //$_POST = array_map('stripslashes_deep', $_POST); }
    $val_cn = trim(preg_replace('/\s+/', ' ',
    $_POST['contact_name']));
    $val_cn = mysql_real_escape_string($val_cn); // Just want to
    see the effect of this function
    $cn_html = htmlentities($val_cn); // Just want to see the
    effect of this function
    if (!preg_match("/^[-a-z'\s]{5,10}$/i", $val_cn))
    { $errors [] = 'Invalid contact name: ' . $val_cn . ' ' .
    $cn_html; }
    else
    { $errors [] = 'Valid contact name: ' . $val_cn . ' ' .
    $cn_html; }
    if (sizeof($errors) > 0)
    // format and display error list
    { echo "<p class=\"val_err\"> Contact format
    error.</p>";
    echo "<div class=\"val_err\"><ul>";
    foreach ($errors as $e)
    { echo "<li>$e</li>"; }
    echo "</div></ul>"; }
    Any help much appreciated.
    Regards.
    Patrick

  • Alphanumeric and pipe delimiter regular expression validation

    i have a header in file like below
    EMP_ID|EMP_NAME|DEPARTMENT|SALARY|ACTIVE1
    passed to a string
    String test = "EMP_ID|EMP_NAME|DEPARTMENT|SALARY|ACTIVE1";
    I have to check if the header has only alphanumeric and pipedelimiter is allowed.
    other than these i need to raise an error.
    Any sugestions.

    hi rp0428  thanks for ur suggestion.
    yes i found string pattern matching.
    public boolean isAlphaNumeric(String s){
       String pattern= "^[a-zA-Z0-9]*$";
       if(s.matches(pattern)){
       return true;
       return false;  
    but i am looking for regexp which matches pipe delimiter as well like
    EMP_ID|EMP_NAME|DEPARTMENT|SALARY|ACTIVE1
    should return true. else if
    EMP_ID , EMP_NAME , DEPARTMENT , SALARY ,, ACTIVE1
    other than pipe delimiter like comma or space it should throw error message.
    thanks.

  • Item Validation using Regular Expression

    Hi,
    I am trying to apply a Validation to a text field item, with the type as Regular Expression.
    The text input into the field should be in a HH:MM:SS format, ie 05:30:00 (for 5:30am).
    The text I am placing in the 'Validation Expression 2' box is:
    [0-2][0-9]\:[0-5][0-9]\:[0-5][0-9]
    This doesn't seem to work and I get an error message when I enter text in the correct format.
    I have even tried to use other comparisons, for example:
    or
    .{8}
    but these still give me an error message.
    Anyone have any ideas?

    Thanks for your help Flavio, the Regular Expression tool is really helpful.
    When I use this tool to compare strings with my regular expression, I get output = TRUE, which means I'm getting it right, but for some reason when I copy the same Regular Expression syntax into APEX, it doesn't work.
    I try to input correct strings into the field that is validated by the Reg Expr, but it still gives me an error.
    It seems to be something I am doing wrong within the application, but I can't figure out what I'm missing.
    I am creating an Item Level Validation with details:
    Type: Regular Expression
    Validation Expression 1: P23_BUS_DAY_COVERAGE_START
    Validation Expression 2: ^(([0-1][0-9])|(2[0-3])):[0-5][0-9]:[0-5][0-9]$
    Has anyone had similar problems using regualr expression validation in APEX?

Maybe you are looking for