Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Form Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Custom validation

Go to End

4 Posts   3447 Views


Community Member, 8 Posts

11 February 2009 at 8:58pm

Hello friends,
I am using silverstripe 2.3.0 rc1

I want to use custom validation on the phone field, please guide me in the same, I want to use javascript for validation

here is code snippet

function Form() {
return new Form($this, "Form", new FieldSet(

// List your fields here
new TextField("ContactPerson", "Contact Person"),
new EmailField("Email", "Email address"),
new DropdownField("Reason", "Your Reason", array(
"Sales" => "Sales",
"Marketing" => "Marketing")),
new PhoneNumberField( $name = "PhoneNumber",
$title = "Phone Number "
new TextareaField( $name = "Remarks",
$title = "Remark",
$rows = 8,
$cols = 3)

), new FieldSet(

// List the action buttons here
new FormAction("SubmitAction", "Submit"),
new ResetFormAction("ClearAction","Clear")

), //new CustomValidator($javascriptCode)

//new CustomValidator("<script>'new.html')</script>")
//new ContactFormValidation()
new RequiredFields("ContactPerson","Email","Reason","PhoneNumber" )

reply become appreciable.
please hurry..
Thank You

Nexus Rex

Community Member, 8 Posts

3 May 2009 at 2:24am

I need help as well figuring out how to disable/enable some fields according to the state of a radio button.


Are you over 18? () Yes () No
If No:
Parent's Email: __________________________

Why does it seem that 70% or more of good questions on this forum go unanswered? I think this forum's lack of quick user help is going to hurt SS.


Community Member, 108 Posts

19 May 2009 at 4:43am

Hi Dipak,

Hey did you ever get the customvalidation to work with the javascript?

I have the exact same situation, but can't figure it out to save my life.

What did you end up doing?

I simply want to add to the required field validation and add a validator for a phonefield to be at least 10 digits in length.

Let me know if you solved this,



Community Member, 8 Posts

8 July 2009 at 8:16pm

Hi Terry, Dipak,

Did you guys find a solution for that validation and your problems?

Please let me know.