CustomFields - suggestion for new validation sub

Post your requests for addons here, and discuss any addons in development here, as well.
Once an addon has completed development, it will be released in the "Addon Release" forum.

Moderator: Spunkmeyer

CustomFields - suggestion for new validation sub

Postby SrNupsen » Mon Apr 10, 2006 4:31 pm

I have a suggestion for a small validation sub to be included in the next version of CustomFields. The purpose is to check for "a valid file name".

Perhaps the most handy would be to check that the file uploaded only contains a-z/A-Z, underscores and 0-9.

This way I won't have to be concerned about my users getting into trouble when posting pictures etc.

SrNupsen
-----------------------------------------------------------------------------------------------------
Coranto is free software. I am available for custom work or troubleshooting.

http://www.sundaune.no - transkripsjon, webdesign, nettsider, tekstbyrå
http://www.vagbladet.no - satire, politikk, kultur, sport, nettavis
-----------------------------------------------------------------------------------------------------
SrNupsen
 
Posts: 2229
Joined: Tue Jan 09, 2007 6:46 pm
Location: Nesodden, outside Oslo, Norway

Postby bozoka45 » Tue Apr 11, 2006 3:56 am

This might not work because my regexp stinks, but I'm fairly certain I'm on the right path. You can simply use a regexp that checks for those values, and those values only.

Code: Select all
/^([\w|\.])*?$/


Test it out, but it should work for alphanumerics only.
User avatar
bozoka45
 
Posts: 1159
Joined: Sun Mar 23, 2003 8:38 pm
Location: New Orleans

Postby Parahead » Tue Apr 11, 2006 6:05 pm

If the regexp works, then all you have to do is incorporate it in a validation sub and place it in cruser.pl and it will be available to choose from the validation dropdown. Check out the addon docs for an example of how to create such a validation sub.
Yes, I am still around...
www.parahead.com/coranto/
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden

Postby faithless » Tue Apr 11, 2006 11:55 pm

bozoka45 wrote:
Code: Select all
/^([\w|\.])*?$/

\. matches for the actual . (dot) sign.
. matches for any characters at all, including non-alphanumerics.
In your pattern, \w matches for alpha characters, so in order to catch underscores and numerics, you probably need to add \d and _ into the [] brackets.

* match zero or more any character.
? match zero or one character.
In this case, since it's a user name, we probably want to match one or more. Hence + would probably be more suitable. :)

Somthing like the one below might just do the trick:
Code: Select all
/^([\w|\_|\d]+)$/


Additional Readings:
http://free.beyonddream.com/CGITutorial/pattern.html
faithless
 
Posts: 1335
Joined: Wed Oct 16, 2002 4:17 pm
Location: Infront of the Computer

Postby bozoka45 » Wed Apr 12, 2006 12:19 am

So is this page wrong about regexp?

\w Match "word" character (alphanumeric plus "_")
User avatar
bozoka45
 
Posts: 1159
Joined: Sun Mar 23, 2003 8:38 pm
Location: New Orleans

Postby SrNupsen » Wed Apr 12, 2006 9:08 am

Parahead wrote:If the regexp works, then all you have to do is incorporate it in a validation sub and place it in cruser.pl and it will be available to choose from the validation dropdown. Check out the addon docs for an example of how to create such a validation sub.


I know - my suggestion was to include it with the next release :)

SrNupsen
-----------------------------------------------------------------------------------------------------
Coranto is free software. I am available for custom work or troubleshooting.

http://www.sundaune.no - transkripsjon, webdesign, nettsider, tekstbyrå
http://www.vagbladet.no - satire, politikk, kultur, sport, nettavis
-----------------------------------------------------------------------------------------------------
SrNupsen
 
Posts: 2229
Joined: Tue Jan 09, 2007 6:46 pm
Location: Nesodden, outside Oslo, Norway

Postby faithless » Wed Apr 12, 2006 10:43 am

bozoka45 wrote:So is this page wrong about regexp?

\w Match "word" character (alphanumeric plus "_")


Woops. my bad. haha. It's correct.
I'm always under the impression that \w consists of a-z and A-Z only.
In that case, I guess it can be shortened to
Code: Select all
/^([\w|\_]+)$/


:oops:
faithless
 
Posts: 1335
Joined: Wed Oct 16, 2002 4:17 pm
Location: Infront of the Computer

Postby Parahead » Wed Apr 12, 2006 4:43 pm

SrNupsen wrote:
Parahead wrote:If the regexp works, then all you have to do is incorporate it in a validation sub and place it in cruser.pl and it will be available to choose from the validation dropdown. Check out the addon docs for an example of how to create such a validation sub.

I know - my suggestion was to include it with the next release :)
Okidoki, wasn't sure so just wanted to point it out. Anyway, this thread is bookmarked now... :-)
Yes, I am still around...
www.parahead.com/coranto/
User avatar
Parahead
 
Posts: 4837
Joined: Fri Jan 12, 2007 8:54 pm
Location: Stockholm - Sweden


Return to Addon Development and Requests

Who is online

Users browsing this forum: No registered users and 2 guests

cron