This topic is locked

Restrict field values

12/16/2008 8:13:33 PM
ASPRunnerPro General questions
P
Philip author

Hi
I would like to restrict users to enter just certain characters / values to a text field. These can be A 1 2 3 or _any_combination of that.

I think I can use a "Before Add Event" for that. Any idea how I can restrict that?
Regards,

Philip

J
Jane 12/17/2008

Philip,
use Before record added event on the Events tab for this purpose.

All entered values are stored in the dict collection, I.e. dict("Field1"), dict("Field2"), etc.

P
Philip author 12/17/2008

Philip,

use Before record added event on the Events tab for this purpose.

All entered values are stored in the dict collection, I.e. dict("Field1"), dict("Field2"), etc.


Jane

yes, but my problem is to define an if-statement for this purpose :-)

Any help or advise is appreciated.
Philip

J
James_Parker 1/5/2009



Jane

yes, but my problem is to define an if-statement for this purpose :-)

Any help or advise is appreciated.
Philip


Did you resolve this Philip? I am looking to achieve the same thing
Thanks,

Jim

P
Philip author 1/5/2009

Jim,
no :-(
Philip

Sergey Kornilov admin 1/5/2009

You can try something like this in BeforeAdd event. This is just a sample and you might need to adjust it according to your needs.

set regEx = New RegExp

regEx.IgnoreCase = False

regEx.Pattern = "[A123]+$"

if regEx.Test(dict("FieldName")) then

BeforeAdd=True

else

BeforeAdd=False

end if
P
Philip author 1/6/2009

You can try something like this in BeforeAdd event. This is just a sample and you might need to adjust it according to your needs.


set regEx = New RegExp

regEx.IgnoreCase = False

regEx.Pattern = "[A123]+$"

if regEx.Test(dict("FieldName")) then

BeforeAdd=True

else

BeforeAdd=False

end if


Sergey,

this code works fine - many thanks.

Within my Add-page I have several fields to be checked with different patterns. Is that possible within the same event anf if YES how?
Philip

J
Jane 1/6/2009

Philip,
here is a sample:

set regEx = New RegExp

regEx.IgnoreCase = False

set regEx2 = New RegExp

regEx2.IgnoreCase = False

regEx.Pattern = "[A123]+$"

regEx2.Pattern = "[A123]+$"

if regEx.Test(dict("FieldName")) and regEx2.Test(dict("FieldName2")) then

...

P
Philip author 1/7/2009

Jane,
many thanks - works great!
Philip

P
Philip author 1/9/2009

You can try something like this in BeforeAdd event. This is just a sample and you might need to adjust it according to your needs.


set regEx = New RegExp

regEx.IgnoreCase = False

regEx.Pattern = "[A123]+$"

if regEx.Test(dict("FieldName")) then

BeforeAdd=True

else

BeforeAdd=False

end if


Sergey,

thanks again for this code. One problem is left: With regEx.Pattern = "[A123]+$" I expected that only the values A123 are allowed. In fact users can enter as well "A,1,2,3" or "A 1 2" (values separated by comma or blank. Is there a way to prevent that?
Regards,

Philip