Sign in to follow this  
Followers 0
RobertJFP

Regular Expression Frustration

7 posts in this topic

All,

I am trying to use a regular expression to validate the author field for a news item submission to our RSS feed. The pattern is:

emailaddress@domain.ext (Firstname Lastname)

The RegEx that I have designed is:

^[a-zA-Z0-9-_\.]+\@[a-zA-Z0-9-_\.]+\.(com|org|net|mil|edu|ca|co.uk|com.au|gov)\s\([A-Z][a-z]+\s[A-Z][a-z]+\)$

When I tried this in 2 different online validators, I get the results I expect. When I try it in my page, http://www.sellingpower.com/test/admin/rss/News_Item.asp, it fails on a string that passes on the validators and that I think should pass. I am at a loss to understand why.

Validation script is:

function Validate_News_Item_Form (theForm)

{

var URLRegExp = new RegExp('^(http?://|ftp://)?(www\.)?[a-zA-Z0-9-\.]+\.(com|org|net|mil|edu|ca|co.uk|com.au|gov)$','');

var emailRegExp = new RegExp('^[a-zA-Z0-9-_\.]+\@[a-zA-Z0-9-_\.]+\.(com|org|net|mil|edu|ca|co.uk|com.au|gov)\s\([A-Z][a-z]+\s[A-Z][a-z]+\)$','');

var isValid = true;

if (theForm.Title.value == '')

{

window.alert('Title cannot be blank.');

theForm.Title.focus();

isValid = false;

}

else if (theForm.URL.value == '')

{

window.alert('URL cannot be blank.');

theForm.URL.focus();

isValid = false;

}

else if (!URLRegExp.test(theForm.URL.value))

{

window.alert('URL does not appear to be valid.');

theForm.URL.focus();

isValid = false;

}

else if (theForm.Description.value == '')

{

window.alert('Description cannot be blank.');

theForm.Description.focus();

isValid = false;

}

else if (theForm.Description.length > 1028)

{

window.alert('Description is too long.');

theForm.Description.focus();

isValid = false;

}

else if (theForm.Category.value == '')

{

isValid = window.confirm('Category is blank.');

if (!isValid)

{

theForm.Category.focus();

}

}

else if (theForm.Author.value == '')

{

isValid = window.confirm('Author is blank.');

if (!isValid)

{

theForm.Author.focus();

}

}

else if (!emailRegExp.test(theForm.Author.value))

{

window.alert('Author does not appear to be in the right format.\nemailaddress@domain.ext (Firstname Lastname)');

theForm.Author.focus();

isValid = false;

}

else if (theForm.Active_Date.value == '')

{

window.alert('Active Date cannot be blank.');

theForm.Active_Date.focus();

isValid = false;

}

else if (!checkDate(theForm.Active_Date))

{

window.alert('Active Date is not a valid date.');

theForm.Active_Date.focus();

isValid = false;

}

else if (theForm.Expire_Date.value == '')

{

window.alert('Expire Date cannot be blank.');

theForm.Expire_Date.focus();

isValid = false;

}

else if (!checkDate(theForm.Expire_Date))

{

window.alert('Expire Date is not a valid date.');

theForm.Expire_Date.focus();

isValid = false;

}

else if (Date.parse(theForm.Active_Date.value) > Date.parse(theForm.Expire_Date.value))

{

window.alert('Expire Date cannot be before Active Date.');

theForm.Active_Date.focus();

isValid = false;

}

return isValid;

}

I realize that this is not an Autoit issue but it came up in GoodSearch.com as a RegEx forum so I am hoping I can get help from someone.

Thank you in advance.

Respectfully,

Robert

Share this post


Link to post
Share on other sites



Make sure there aren't any null chars. PCRE as used in AutoIt won't search past a null char. If you used copy & paste into the regexp validator, null chars will not be present in the test string.

Share this post


Link to post
Share on other sites

All,

I am trying to use a regular expression to validate the author field for a news item submission to our RSS feed. The pattern is:

emailaddress@domain.ext (Firstname Lastname)

The RegEx that I have designed is:

^[a-zA-Z0-9-_\.]+\@[a-zA-Z0-9-_\.]+\.(com|org|net|mil|edu|ca|co.uk|com.au|gov)\s\([A-Z][a-z]+\s[A-Z][a-z]+\)$

When I tried this in 2 different online validators, I get the results I expect. When I try it in my page, http://www.sellingpower.com/test/admin/rss/News_Item.asp, it fails on a string that passes on the validators and that I think should pass. I am at a loss to understand why.

It costs Jon money to host this site, and he does that for AutoIt.

All I can tell you is that pattern works fine in AutoIt:

_CheckPattern('dingle.berry@yourspace.com (Dingle Berry)')
_CheckPattern('dingle.berry@yourspace.com')

Func _CheckPattern($sData)
    $sRegExp = '^[a-zA-Z0-9-_\.]+\@[a-zA-Z0-9-_\.]+\.(com|org|net|mil|edu|ca|co.uk|com.au|gov)\s\([A-Z][a-z]+\s[A-Z][a-z]+\)$' 
    If StringRegExp($sData, $sRegExp, 0) Then
        MsgBox(64, "Success", "Matches pattern: " & $sData, 5)
    Else
        MsgBox(16, "Failure", "Does not match pattern: " & $sData, 5)
    EndIf
EndFunc   ;==>_CheckPattern

<_<


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

We came up as a RegExp forum????? Do I talk about it that much? <_<

I wrote a email validation regexp some time ago I believe... "_IsValidEmail" more than likely.

I'll see if I can find the link and or the udf I wrote.

Edit:

Here's the link:

http://www.autoitscript.com/forum/index.ph...st&p=308105

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Well, Smoke, you ARE the resident RegEx nerd.


Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Well, Smoke, you ARE the resident RegEx nerd.

Well, anything that can be done with RegExp can be done with a combination of the other string functions... but if I can do in 1 to 5 lines of code, what would take me 20 to 300 lines with the other string funcs... why not learn how to use it <_< ... Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Well, Smoke, you ARE the resident RegEx nerd.

Hi,

I believe Ron can do very much, but being a RegEx-nerd ? <_<:)

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0