Regular expression form validation

I have a form field that I currently validate using
<cfinput pattern="^([a-zA-Z]{2}$" validate="regular_expression"
Type="text" required="yes"> (other attributes also including
name, etc). Anyway, this validates that the input must be 2
letters, but know I need to validate the field so that "NA" is
allowed. Is there a way to do that?

The regular expression
[^NA]
causes NA to be escaped.
The expression
[NA]
causes NA to NOT be escaped.
So if I read your code right, you should insert a [^NA] but
if this fails, do the other = [NA]
I always need to test these things :-)
Hope this helps,
Hans

Similar Messages

  • Using regular expressions for validation in i18n

    Can we use regular expressions for validation of inputs in a java application taking care of i18N aspects too. Zip code for different locales are different. Can we use regular expressions to validate zipcode inputs from different locales

    hi,
    For that shall i have to create individual patterns for matching the inputs from different locales or a single pattern will do in the case of validating phone nos. around the world, zip codes etc. In case different patterns are required, programmer should have a konwledge of difference in patters for different locales.
    regards
    sdas

  • Regular Expression to validation email address

    I want to validate an Email address and I need a regular expression for validating the email address.
    Email address requirement:
    1) It should not start with numbers, say like [email protected]
    2) It should be limited to 65 characters long including domain name.
    3) It should not have numeric domain names like [email protected]
    ANy inputs will be great.
    Thanks

    AccountUser1 wrote:
    Oh ok. If domain names can begin with numbers and its valid, then I'do like to incorporate it. Thanks for the info.
    In that case let me rephrase my requirement:
    Email address requirement:
    1) It should not start with numbers, say like [email protected]
    2) It should be limited to 65 characters long including domain name.So, you just arbitrarily refuse to deal with entire classes of email addresses? Why?

  • Using regular expressions for validating time fields

    Similar to my problem with converting a big chunk of validation into smaller chunks of functions I am trying to use Regular Expressions to handle the validation of many, many time fields in a flexible working time sheet.
    I have a set of FormCalc scripts to calculate the various values for days, hours and the gain/loss of hours over a four week period. For these scripts to work the time format must be in HH:MM.
    Accessibility guidelines nix any use of message box pop ups so I wanted to get around this by having a hidden/visible field with warning text but can't get it to work.
    So far I have:
    var r = new RegExp(); // Create a new Regular Expression Object
    r.compile ("^[00-99]:\\] + [00-59]");
    var result = r.test(this.rawValue);
    if (result == true){
    true;
    form1.flow.page.parent.part2.part2body.errorMessage.presence = "visible";
    else (result == false){
    false;
    form1.flow.page.parent.part2.part2body.errorMessage.presence = "hidden";
    Any help would be appreciated!

    Date and time fields are tricky because you have to consider the formattedValue versus the rawValue. If I am going to use regular expressions to do validation I find it easier to make them text fields and ignore the time patterns (formattedValue). Something like this works (as far as my very brief testing goes) for 24 hour time where time format is HH:MM.
    // form1.page1.subform1.time_::exit - (JavaScript, client)
    var error = false;
    form1.page1.subform1.errorMsg.rawValue = "";
    if (!(this.isNull)) {
      var time_ = this.rawValue;
      if (time_.length != 5) {
        error = true;
      else {
        var regExp = /^([01]?[0-9]|2[0-3]):[0-5][0-9]$/;
        if (!(regExp.test(time_))) {
          error = true;
    if (error == true) {
      form1.page1.subform1.errorMsg.rawValue = "The time must be in the format HH:MM where HH is 00-23 and MM is 00-59.";
      form1.page1.subform1.errorMsg.presence = "visible";
    Steve

  • Regular Expressions - Email Validation

    According to RFC-2822 and RFC-2821 specifications the local part of email addresses are allowed to contain a whitespace character as long as it is within quotations. The rest of my regular expression works fine I am battling to find out how to match the above mentioned pattern. Here is the first part of my expression...
    ([\"(\\w|\\s|\\p{Punct}){1,}\"])
    If there is a whitespace character I need to make sure it is surrounded with quotations
    Any help will be much appreciated!

    AmitChalwade123456 wrote:
    it's client side validation ( java script regex) must be used ! Since when are client side validations recommended above server side validations?
    What would happen if the client disabled Javascript or hacked the Javascript code?
    i think
    /\S+@\S+\.\S+/;this might help uThis makes no sense. It just checks on availability of the '@' and '.' in that order in the email address. It doesn't check it if contains valid characters nor checks if it is surrounded by quotes if the actual address contains spaces.

  • Need a Better Regular Expression for Validating Dates

    I have data coming from file with date in the format DD-MON-YY.
    I have created the following regular expression:
    '^([0-2]{1}[0-9]{1}|[3]{1}[0-1]{1})-(JAN|FEB|MAR|A PR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC|Jan|Feb|Mar|Apr |May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-[[:digit:]]{2}$'
    However, it doesn't catch dates like 31-APR, 29-FEB. Can someone make changes to it to make it foolproof
    WITH temp AS
    (SELECT '29-FEB-07' AS COL1 FROM DUAL
    UNION ALL
    SELECT '31-APR-08' FROM DUAL
    UNION ALL
    SELECT '32-JAN-08' FROM DUAL
    UNION ALL
    SELECT '29-MAR-08' FROM DUAL
    UNION ALL
    SELECT '31-JAN-08' FROM DUAL)
    SELECT COL1,
    CASE WHEN REGEXP_LIKE(COL1,'^([0-2]{1}[0-9]{1}|[3]{1}[0-1]{1} )-(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC |Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)- [[ :digit:]]{2}$')
    THEN 'VALID'
    ELSE 'INVALID'
    END
    FROM TEMP;

    Hi,
    Please check this function.
    The function works for the dates in the format 'DD-MON-YYYY','DD/MON/YYYY'.
    create or replace function date_validation_f(v_date varchar2) return varchar2 is
    v_ip_date     date;
    v_ip_date_ch  varchar2(20);
    v_ip_year  number;
    v_ip_month char(3);
    v_ip_day   number;
    v_return   varchar2(10);
    v_leap_year_check number :=0 ;
    type v_month_name_typ      is varray (12) of char(3);
    type v_month_last_day_typ  is varray (12) of number(2);
    v_month_name     v_month_name_typ    :=v_month_name_typ('JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC');
    v_month_last_day v_month_last_day_typ:=v_month_last_day_typ(31,28,31,30,31,30,31,31,30,31,30,31);
    begin
    --Assuming that input date is in the format DD-MON-YYYY or DD/MON/YYYY
    v_return := 'invalid';
    v_ip_date := to_date(v_date);
    v_ip_date_ch := to_char(v_ip_date,'DD-MON-YYYY');
    dbms_output.put_line('v_ip_date_ch := '||v_ip_date_ch);
    v_ip_month   := substr(v_ip_date_ch,4,3);
    dbms_output.put_line('v_ip_month := '||v_ip_month);
    v_ip_day    := substr(v_ip_date_ch,1,2);
    dbms_output.put_line('v_ip_year := '||v_ip_year);
    v_ip_year     := to_number(substr(v_ip_date_ch,8,4));
    dbms_output.put_line('v_ip_day := '||v_ip_day);
    -- Ckecking for leap year
    if MOD(v_ip_year,4)=0 then
      if MOD(v_ip_year,100)=0 then
        if MOD(v_ip_year,400)=0 then
           v_leap_year_check:=1;
        end if;
      else
           v_leap_year_check:=1;
      end if;
    end if;
    if v_leap_year_check = 1 then
       v_month_last_day(2):=29;
    end if;
    for i in 1..12
    loop
    if v_month_name(i)=upper(v_ip_month) then
         if v_ip_day between 1 and v_month_last_day(i) then
            v_return := 'valid';
            exit;
        else
            v_return := 'invalid';
            exit;
        end if;
    end if;
    end loop;
    dbms_output.put_line('v_return := '||v_return );
    return v_return;
    exception
    when others then
    return v_return;
    dbms_output.put_line(SQLERRM);
    end;you can use this function in SELECT statement.
    Edited by: Sreekanth Munagala on Nov 13, 2008 11:25 PM

  • Regular Expression item validation for email address

    Hi,
    Does anyone know of a regular expression I can use to validate an email address field? I am using Apex 3.2.
    Your help would be much appreciated.
    Thanks,
    ca84

    ^((\s*[a-zA-Z0-9\._%-]+@[a-zA-Z0-9\.-]+\.[a-zA-Z]{2,4}\s*[,;:]){1,100}?)?(\s*[a-zA-Z0-9\._%-]+@[a-zA-Z0-9\.-]+\.[a-zA-Z]{2,4})*$

  • Infopath throws error "only specific pattern allowed" when use regular expression for validation in schema

    This is MS info path question, I could not find specific forum for Info-Path So asking my question here
    I am creating Info-Path form from schema. In the schema, the filename has restriction that it can only have extension .pdf or .PDF. But while filling out the form even if I type filename with extension ".pdf", I still see error "only
    specific pattern allowed".
    Below is my schema I used to create form
    <?xml version="1.0" encoding="utf-8" ?>
    <xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="Document">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="FileName" type="FileNameType"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    <xs:simpleType name ="FileNameType">
    <xs:restriction base="xs:string">
    <xs:pattern value="^.*\.(pdf|PDF)$"/>
    <xs:minLength value="1" />
    <xs:maxLength value="128" />
    </xs:restriction>
    </xs:simpleType>
    </xs:schema>

    Hi
    This is the forum to discuss questions about Microsoft Office development. For your question, I recommend you post the question to the Answers forum for Infopath
    Microsoft Community for​ InfoPath​
    By the way, you can get support from here.  Support for Microsoft InfoPath
    Thank you for your understanding.
    Best Regards
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Simultaneous Client and Server Form Validation using Custom Tag Library

    I am developing a custom tag library for validator tags
    which are capable of doing client side validation (Javascript)
    and server side (Java). My problem is with the development
    of a regular expression based validator. Because of differences
    in the way Javascript and Java handle regular expressions
    i can not use the same regular expression for both types of
    validation. Is there any way to convert a valid regular
    expression from the java.util.regex format into the Javascript
    format or vice versa? My major problems are with the (or, ||)
    statements and the user of backslashes.

    If you are speaking of RE syntax flavours, they are basically the same(namely perl5 flavour). Any expression that works in JS should work in j.u.regex too.
    Though, their usage is quite different.
    So, there is no need for convertion of expressions.
    But porting the code may be not so trivial.

  • Regular Expression as page item

    Hello,
    I´m doing a page item validation using Regular Expressions, but my Regular Expression is Dynamic. I have another page item called VL_REGEXP where I set a value of regular expression.
    But, when I write VL_REGEXP as validation expression, it doesn´t test the condition. It only tests when I put the value of the regular expression.
    So, what would I do to pass this Dynamic Regular Expression for validation?
    Example of my settings:
    -- It doesn´t work
    Type of validation:
    Item / Column in expression 1 matches Regular Expression in Expression 2
    Expression 1
    P12_CD_ACCOUNT
    Expression 2
    P12_VL_REGEXP   -- this is what i need!
    -- It works
    Type of validation:
    Item / Column in expression 1 matches Regular Expression in Expression 2
    Expression 1
    P12_CD_ACCOUNT
    Expression 2
    ^(\d\d\.\d\d\d\.\d)+$
    thanks
    Bsalvador

    Not sure if the required substitution processing is supported in the validation expression, but if it is you need to reference the page item using the static text substitution syntax:
    Type of validation:
    Item / Column in expression 1 matches Regular Expression in Expression 2
    Expression 1
    P12_CD_ACCOUNT
    Expression 2
    &P12_VL_REGEXP.

  • How to use Regular expression

    Hi,
    I have a file that contains this format (separated by ;(semicolon) ):
    user id;user name;email address;password;integer;list of integer(separated by ,(comma))
    below is the example data :
    abc;Abc;[email protected];password1;1;1,2
    def;Def;[email protected];password;2;1,2,3
    ghi;Ghi;[email protected];password;2;1
    my question is how to verify the valid input for each row using regular expression..? TQ

    @Op. Doing a correct validation of e-mailaddresses
    is very hard using regular expressions (doingbasic
    validation is however easy)
    http://www.regular-expressions.info/email.html
    I like the RFC 822 compliant regexp :)

  • Problem creating a regular expression

    Hi Everyone
    I am trying to create a regular expression for validating a password string for the following given rule -
    It must contain atleast any two of following 4 classes of characters -
    1. lowercase letters.. a - z
    2. uppercase letters.. A - Z
    3. digits.. 0 - 9
    4. Special characters.. !@#$%^&*()/?><
    I m having a hard time creating such regular expression. I will really appreciate if someone can help me with this.

    [http://google.com/search?q=regular+expression+password+validation+site:forums.sun.com]

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

  • Field validation by regular expressions?

    Hi everyone,
    I just started with SoD and I'd like to ensure that some field values consists of alphabetic characters only (FirstName, LastName...). I failed to create an adequate expression. Is there a possibility to use regular expressions?
    TIA
    Michael

    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.

  • Regular expression validates in DB but not with a apex regexp validation?

    Hi all,
    sorry if I overlooked a similar post:
    I have a page with a form and item containing this email address [email protected] that item I've made a validation of type regular expression.
    I've got my item in
    Validation expression 1 P420_EMAIL and in
    Validation expression 2 '^[a-zA-Z0-9\_\.\-]+@[a-zA-Z0-9\_\.\-]+\.[a-zA-Z]{2,4}$'If I do
    select '[email protected]'
    from    dual
    where   regexp_like('[email protected]' , '^[a-zA-Z0-9\_\.\-]+@[a-zA-Z0-9\_\.\-]+\.[a-zA-Z]{2,4}$') on the DB this returns my email address as expected.
    If I submit my form with that same email address I get my error message from my validation.
    What's the difference I'm missing between the Apex way and the DB way of validating with this regular expression?
    Thanks a lot!
    Kind regards,
    Diana

    why not rewrite the validation to the type PL/SQL expression (function returning boolean) and put this in the expression1:
    regexp_like(:P420_EMAIL , '^[a-zA-Z0-9\_\.\-]+@[a-zA-Z0-9\_\.\-]+\.[a-zA-Z]{2,4}$')
    then you're absolutely sure you are doing the right validation. If that doesn't work, try displaying the result of the validation on screen to see what goes wrong.

Maybe you are looking for