Form validation function (true or false) - Javascript

I need a form validation function that returns true or false if it is validate. For example, given an HTML document with the following content within the <body> tag: This function should return true, while given the following content:

<form>       <input type="radio" id="type_person" name="type" value="person" checked/>       <input type="radio" id="type_company" name="type" value="company"/>       <input type="text" id="first_name" name="first_name" value="John"/>       <input type="text" id="last_name" name="last_name" value="Doe"/>       <input type="text" id="email" name="email" value="[email protected]"/>       <input type="text" id="company_name" name="company_name" value=""/>       <input type="text" id="phone" name="phone" value="234-567-890"/>     </form> 

your function should return false (the phone number is not correct):

<form>   <input type="radio" id="type_person" name="type" value="person"/>   <input type="radio" id="type_company" name="type" value="company" checked/>   <input type="text" id="first_name" name="first_name" value="John"/>   <input type="text" id="last_name" name="last_name" value="Doe"/>   <input type="text" id="email" name="email" value="[email protected]"/>   <input type="text" id="company_name" name="company_name" value="ACME"/>   <input type="text" id="phone" name="phone" value="12-3"/> </form> 

Empty function:

function solution() {  } 

Replay

Category: javascript Time: 2016-07-31 Views: 33

Related post

  • Form validation functional javascript code 2016-07-01

    Here is a code posted originally on stackoverflow but better suited here as I was suggested. I recently converted a code to what I think is partly at least, functional javascript. It's a web form validation process. At each step of the process, the f

  • Call form validation function by clicking link 2015-12-15

    I want to be able to click a link on my form and have it call the form's validation function (but not actually submit it!). Here's what I've got that's partially working: in form_alter: $form['my_field'][LANGUAGE_NONE][0]['value']['#field_suffix'] =

  • Calling form validation function from new button 2014-03-15

    I've attached a Process button on the node edit form. But on clicking it - in it's validation function form_set_error is not working. In my form_alter I've this code: $form['buttons']['process'] = array( '#type' => 'submit', '#value' => 'Process', '

  • How to bypass required fields in form validation function of a module? 2013-05-09

    I have a form with two radios and two forms related to each of them. These forms have some required fields. user can just check one radio and then fill in one form. but then clicks on submit button drupal gives error for those unselected and empty fi

  • Extending form validation functions 2011-09-22

    How do I pass additional values to #element_validate so they can be used for validation? I'm using hook_form_alter() and Drupal 7. //Example 1 function my_validation_function($form, &$form_state) { //Validation Code } I would like to use: //Example 2

  • How can one add inline JavaScript in the validation function for the Form API? (Drupal 7) 2015-09-28

    This question already has an answer here: drupal_add_js not work in form validation failed 1 answer I found that there is a way to add javascript files in the form validation function as stated here. However, I would like to know how to add javascrip

  • Form validation on modal confirm 2016-01-22

    This is my code. The problem is that the form is submitting when i clicked the confirm button on the modal. The thing is I dont know how to validate the form first before submitting. This is the process I want. 1. The user fill up the field. 2. The u

  • Symfony2 - using form validation in REST API project 2016-01-20

    In a Symfony REST API project and we are implementing a validation for the params passed to the end points. I'm trying to using forms for this purpose but they don't seem to work as expected. Given this end point as example: GET /users/ which accepts

  • Customize Parsley form validation styles in AngularJS module 2016-02-03

    What I'm trying to do is to customize the style of my "error" messages that is thrown by Parsley. Unfortunately this is simpler said than done because my form that has to be validated is in a template page that gets pulled into a <main ui-vie

  • Using excel, how can I count the number of cells in a column containing the text "true" or "false"? 2010-05-09

    I have a spreadsheet that has a column of cells where each cell contains a single word. I would like to count the occurrences of some words. I can use the COUNTIF function for most words, but if the word is "true" or "false", I get 0.

  • How to save validated third party API data if form validation fails 2013-06-20

    Here's my issue. During user register I'm adding fields via form_alter and creating a stripe account. When validation fails $form_state gets wiped out and when the user passes through validation again a second account gets created. I'm thinking about

  • Give user empty form on form validation error 2013-11-25

    I'm using braintree.js with a custom form. For those not familiar, braintree.js does client side encryption of the form fields before submission to the server. On my end I get a bunch of gibberish (this is expected). If a form validation error occurs

  • Trigger standard new/edit form validation from custom button code behind 2015-12-10

    I've got a standard new and edit form with one custom button on it. I want to trigger the usual form validation, when the button is clicked and ONLY execute the code behind the button when the form validation is true. Is it possible to trigger the st

  • mixed AJAX/Javascript form validation check 2011-09-12

    I've got a form, for which the "Send" button should only be available, upon each form field being validated. For most of my check, I call a function checkFormValue() which is a function gathering all the simple checks, give warning where check f

  • Instant Form Validation Using JavaScript 2013-01-23

    HTML5 introduces a couple of new attributes for implementing browser-based form validation. The pattern attribute is a regular-expression that defines the range of valid inputs for textarea elements and most types of inputs. The required attribute sp

  • Javascript form validating 2016-02-12

    I am having a bit of trouble with my form validation JavaScript. I have two working form validations but one is practically no longer needed. So I am trying to combined them into one function. The problem is that if I try I no longer get the input ba

  • kpr() in my form validation and submit function is not being called 2013-08-13

    In my form validation and submit functions, kpr() is not being called. Is there a better way to check that I'm in those functions? If kpr() isn't ideal to output my $form_state array, then what is ideal? --------------Solutions------------- Everythin

  • JavaScript form validation: improve on 'good, but not good enough' 2013-11-26

    I recently received a 'good, but not good enough' rating on a coding exercise I was asked to perform. It was to validate that if "Product complaint" option was selected that Product name, Product size, Use-by date and Batch code fields all neede

  • Form Validation - check box with Javascript 2016-01-19

    I have some information I am trying to validate when a user clicks a "confirm" check box. The issue is this is data pulled in from an Access database so the form field IDs have variables. Here is the check box I am using to trigger the event: &l

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.444 (s). 13 q(s)