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

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 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

  • 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

  • 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...

  • 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

  • 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?

  • Field validation regular expression to accept only numbers

    Hello.
    I would like to have a field validation regular expression to accept only numbers - no characters. The list of pre-packaged regular expressions that are included with ApEx does not contain this and I am not a very good regular expression writer. Can anyone help?
    Thanks!
    Boris

    Under the Regular Expression validation all you need to have is:
    ^[[:digit:]]$For the email address it just depends how detailed you want it:
    ^((?>[a-zA-Z\d!#$%&'*+\-/=?^_`{|}~]+\x20*|"((?=[\x01-\x7f])[^"\\]|\\[\x01-\x7f])*"\x20*)*(?<angle><))?((?!\.)(?>\.?[a-zA-Z\d!#$%&'*+\-/=?^_`{|}~]+)+|"((?=[\x01-\x7f])[^"\\]|\\[\x01-\x7f])*")@(((?!-)[a-zA-Z\d\-]+(?<!-)\.)+[a-zA-Z]{2,}|\[(((?(?<!\[)\.)(25[0-5]|2[0-4]\d|[01]?\d?\d)){4}|[a-zA-Z\d\-]*[a-zA-Z\d]:((?=[\x01-\x7f])[^\\\[\]]|\\[\x01-\x7f])+)\])(?(angle)>)$or...
    [\w-]+@([\w-]+\.)+[\w-]+Hope these help
    Edited by: MikesHotRod on Sep 3, 2008 12:40 PM

  • CFFORM (Flash) Validation with Regular Expressions Not Working

    I am having troubles getting regular expression validation to
    work in a CFFORM. The below code is an extract of a much larger
    form, the first name and last name have a regular expression
    validation...and it doesn't work!
    I'd appreciate any comments/info for help on this, have
    searched high and low on information to get this working...but no
    joy.
    The code is:
    <cffunction name="checkFieldSet" output="false"
    returnType="string">
    <cfargument name="fields" type="string" required="true"
    hint="Fields to search">
    <cfargument name="form" type="string" required="true"
    hint="Name of the form">
    <cfargument name="ascode" type="string" required="true"
    hint="Code to fire if all is good.">
    <cfset var vcode = "">
    <cfset var f = "">
    <cfsavecontent variable="vcode">
    var ok = true;
    var msg = "";
    <cfloop index="f" list="#arguments.fields#">
    <cfoutput>
    if(!mx.validators.Validator.isValid(this,
    '#arguments.form#.#f#')) { msg = msg + #f#.errorString + '\n';
    ok=false; }
    </cfoutput>
    </cfloop>
    </cfsavecontent>
    <cfset vcode = vcode & "if(!ok)
    mx.controls.Alert.show(msg,'Validation Error'); ">
    <cfset vcode = vcode & "if(ok) #ascode#">
    <cfset vcode =
    replaceList(vcode,"#chr(10)#,#chr(13)#,#chr(9)#",",,")>
    <cfreturn vcode>
    </cffunction>
    <cfform name="new_form" format="flash" width="600"
    height="600" skin="halosilver" action="new_data.cfc">
    <cfformgroup type="panel" label="New Form"
    style="background-color:##CCCCCC;">
    <cfformgroup type="tabnavigator" id="tabs">
    <cfformgroup type="page" label="Step 1">
    <cfformgroup type="hbox">
    <cfformgroup type="panel" label="Requestor Information"
    style="headerHeight: 13;">
    <cfformgroup type="vbox">
    <cfinput type="text" name="reqName" width="300"
    label="First Name:" validate="regular_expression" pattern="[^0-9]"
    validateat="onblur" required="yes" message="You must supply your
    First Name.">
    <cfinput type="text" name="reqLname" width="300"
    label="Last Name:" validate="regular_expression" pattern="[^0-9]"
    validateat="onblur" required="yes" message="You must supply your
    Last Name.">
    <cfinput type="text" name="reqEmail" width="300"
    label="Email:" validate="email" required="yes" message="You must
    supply your email or the address given is in the wrong format.">
    <cfinput type="text" name="reqPhone" width="300"
    label="Phone Extension:" validate="integer" required="yes"
    maxlength="4" message="You must supply your phone number.">
    </cfformgroup>
    </cfformgroup>
    </cfformgroup>
    <cfformgroup type="horizontal"
    style="horizontalAlign:'right';">
    <cfinput type="button" width="100" name="cnt_step2"
    label="next" value="Next"
    onClick="#checkFieldSet("reqName,reqLname,reqEmail,reqPhone","new_form","tabs.selectedInd ex=tabs.selectedIndex+1")#"
    align="right">
    </cfformgroup>
    </cfformgroup>
    </cfformgroup>
    </cfformgroup>
    </cfform>

    quote:
    Originally posted by:
    Luckbox72
    The problem is not the Regex. I have tested 3 or 4 different
    versions that all work on the many different test sites. The
    problem is it that the validation does not seem to work. I have
    changed the patter to only allow NA and I can still type anything
    into the text box. Is there some issue with useing Regex as your
    validation?
    Bear in mind that by default validation does not occur until
    the user attempts to submit the form. If you are trying to control
    the characters that the user can enter into the textbox, as opposed
    to validating what they have entered, you will need to provide your
    own javascript validation.

  • Using Regular Expressions in 1.6

    I'm a new HTML DB user. I've been through 1.5 training, but I'm now trying to find my way thru 1.6. In 1.5 I could select Regular Expression as a validation type, within the validation wizard. How do I "tie" a Regular Expression validation to a field within 1.6?

    user447618,
    Regular Expressions were first introduced in SQL and PL/SQL as of Oracle Database 10g. What version of the database are you running?
    Sergio

  • Regular expression for email

    Hi all,
    Can anyone help me to create a regular expression validation for email id? I have tried many combinations from internet regarding this validation, but everyone fails on APEX, although it runs fine in .NET or JAVA.
    Expressions i tried was "^([\w\-\.]+)@((\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z]{2,4}))$", i want to validate email address such as "[email protected]". Can anyone help me in this regard?
    With Regards,
    Sunil Bhatia

    Hello Sunil,
    >> Can anyone help me to create a regular expression validation for email id?
    If you are talking about an email address, it’s not clear to me why you include the ‘http’ string in your regular expression. In any case, I’m using the following:
    ^[a-zA-Z0-9]{1}[a-zA-Z0-9\.\-]{1,}@[a-zA-Z0-9]{1}[a-zA-Z0-9\.\-]{1,}\.{1}[a-zA-Z]{2,4}$Regards,
    Arie.
    Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all.

Maybe you are looking for

  • Some questions about the integration between BIEE and EBS

    Hi, dear, I'm a new bie of BIEE. In these days, have a look about BIEE architecture and the BIEE components. In the next project, there are some work about BIEE development based on EBS application. I have some questions about the integration : 1) ge

  • First Generation iPad No Longer Recognised after iTunes 10.6 and iOS 5.1 updates, help me!

    I recently updated the version of iTunes on my early '06 iMac (17" 1.86GHz Intel Core Duo, 32-bit, 1.5GB RAM, OS X 10.6.8), to version 10.6 and the version of iOS on my first model iPad to 5.1. Since the update, it no longer shows up in iTunes despit

  • What should I do about this phone ?

    around mid mid september last year I bought an iPhone 4s, 16fb black, and I used it on iOS6 (can't remeber which version) since I didnt want bugs from ios7, and I let my frien use my phone for a day or two, because he didmt have a phone to use to tel

  • Need help with formatting a number

    hi all, the problem i am having has been a hot topic over time in java. i have an integer say 123. i want to convert this to a string of 10 characters. how do i pad the first seven spaces with blanks. ex. " 123" in c++ you can use sprintf. how do i d

  • My safari keeps quiting on my iphone?

    My safari keeps quiting on my iphone four please some onee help! also i cant watch vedios on my phone?