Forums

This topic is locked

Using Spry Validation on Dreamweaver CS3

Posted 04 Jan 2008 12:09:59
1
has voted
04 Jan 2008 12:09:59 DAVID KNIGHT posted:
I'm trying to set up data validation so as to validate the 1st part of an entered postcode

The 1st part of Postcodes in the UK is in the format:

X9
XX9
XX99

X represents a character from A-Z
9 represents a number from 0-9

Has anyone any idea how I could achieve this using the Spry Validation text field on a form?

I've been looking into this and the only thing I think I can do is to modify the spryvalidationtextfield.js file.

The section I think I need to modify is:

'zip_uk': {
characterMasking: /[\dA-Z\s]/,
validation: function(value, options) {
//check one of the following masks
// AN NAA, ANA NAA, ANN NAA, AAN NAA, AANA NAA, AANN NAA
return /^[A-Z]{1,2}\d[\dA-Z]?\s?\d[A-Z]{2}$/.test(value);
}

Does anyone know what the characters do?

I'm guessing [A-Z]{1,2} tells it to expect characters from A-Z of either 1 or 2 character length?
but what do the \d and \s and the question marks and the $ symbol all mean?<u></u><u></u><u></u><u></u><u></u><u></u>

Edited by - DAKNIGHTUK on 04 Jan 2008 13:28:51

Replies

Replied 04 Jan 2008 13:51:34
04 Jan 2008 13:51:34 DAVID KNIGHT replied:
I found a website www.webdevelopersjournal.com/articles/jscript_forms2.html which explains what the characters all mean my resultant edited spryvalidationtextfield.js looks like this :

'zip_uk': {
characterMasking: /[\dA-Z\s]/,
validation: function(value, options) {
//check one of the following masks
// AN NAA, ANA NAA, ANN NAA, AAN NAA, AANA NAA, AANN NAA
return /^[A-Z]{1,2}\d{1,2}$/.test(value);
}
Replied 04 Jan 2008 14:02:08
04 Jan 2008 14:02:08 DAVID KNIGHT replied:
I changed the line:

return /^<b>[a-zA-Z]</b>{1,2}\d{1,2}$/.test(value);

to allow the user to input upper or lower case.

The purpose of the spry validation was to limit what the user could enter and block any possiblity of an sql injection attack by not allowing symbol characters

Reply to this topic