Comments (2)
Give this a try:
$.verify.addRules({
cellphone: function(r) {
//pass validation if there is no carrier
if(!$("#carrier").val()) {
return true;
}
//perform cell validation here [Note: r.val() is a shortcut to $(element-being-validated).val() ]
if(/^\d{10}$/.test(r.val())) {
return "You must enter a valid cell-phone number"
}
//passed
return true;
}
});
Now, we can use it
<form>
<select id="carrier">
<!-- dropbox options -->
</select>
<input value="" data-validate="cellphone">
<input type="submit" class="submit">
</form>
from verifyjs.
I appreciate you taking the time to help!
I did try it but the fields didn't get flagged when I entered a cellphone number and left the dropdown select alone, nor did it work when I selected a dropdown option with valid, non-blank data and left the phone number blank.
Here's what I did code-wise:
<div class="clear"></div>
<div id="home_email_list">
<div id="container"> <!-- http://psychostick.com/listmessenger/public/listmessenger.php -->
<form method="post" action="test.php" name="subscribeform" class="pure-form pure-form-aligned">
<input type="hidden" name="group_ids[]" value="1" />
<fieldset id="required_home">
<div class="pure-control-group">
<input type="text" name="firstname" value="" placeholder="First Name" required>
</div>
<div class="pure-control-group">
<input type="text" name="lastname" value="" placeholder="Last Name" />
</div>
<div class="pure-control-group">
<input type="email" name="email_address" value="" placeholder="E-mail" required class="firstemail">
</div>
<div class="pure-control-group">
<input type="text" name="zipcode" maxlength="5" value="" placeholder="Zip Code" required data-validate="number">
</div>
</fieldset>
<fieldset id="optional_home">
<div class="pure-control-group">
<input type="text" name="phone" maxlength="12" value="" placeholder="Cell Number" data-validate="cellphone">
</div>
<div class="pure-control-group">
<select name="carrier" id="carrier">
<option value="">Select Cell Carrier</option>
<option value="">--USA/Canada--</option>
<option value="airtouch.net">Airtouch Pager</option>
<option value="wirefree.informe.ca">Aliant/NBTel</option>
<option value="message.alltel.com">Alltel</option>
<option value="paging.acswireless.com">Ameritech (ACS)</option>
<option value="txt.att.net">AT&T</option>
<option value="mmode.com">AT&T mmode</option>
<option value="txt.bellmobility.ca">Bell Mobility Canada</option>
<option value="bellsouth.cl">Bellsouth</option>
<option value="mobile.mycingular.com">Cingular</option>
<option value="fido.ca">Fido Canada</option>
<option value="messaging.nextel.com">Nextel</option>
<option value="pager.qualcomm.com">Qualcomm</option>
<option value="qwestmp.com">Qwest</option>
<option value="pcs.rogers.com">Rogers Wireless</option>
<option value="email.skytel.com">Skytel Pager</option>
<option value="messaging.sprintpcs.com">Sprint PCS</option>
<option value="tmomail.net">T-Mobile USA</option>
<option value="msg.telus.com">Telus Mobility</option>
<option value="utext.com">Unicel</option>
<option value="email.uscc.net">US Cellular</option>
<option value="vtext.com">Verizon</option>
<option value="voicestream.net">Voicestream</option>
<option value="vmobile.ca">Virgin Mobile Canada</option>
<option value="vmobl.com">Virgin Mobile USA</option>
<option value="">--Elsewhere--</option>
<option value="orange.net">Orange</option>
<option value="sms.orange.nl">Dutchtone/Orange-NL</option>
<option value="kapow.co.uk">Kapow!</option>
<option value="m1.com.sg">MobileOne</option>
<option value="sms.netcom.no">Netcom</option>
<option value="optusmobile.com.au">Optus</option>
<option value="mujoskar.cz">Oskar</option>
<option value="o2online.de">O2 Germany</option>
<option value="mysmart.mymobile.ph">Smart Com (Philippines)</option>
<option value="starhub.net.sg">StarHub (Singapore)</option>
<option value="T-D1-SMS.de">T-Mobile Germany</option>
<option value="t-mobile.co.uk">T-Mobile UK</option>
<option value="gsm1800.telia.dk">Telia Denmark</option>
<option value="mobilpost.no">Telenor</option>
<option value="virginextra.com">Virgin Mobile UK</option>
<option value="vodafone.de">Vodafone Germany</option>
<option value="sms.vodafone.it">Vodafone Italy</option>
<option value="vodafone.pt">Vodafone Portugal</option>
<option value="euromail.se">Vodafone Sweden</option>
<option value="c.vodafone.ne.jp">Vodafone Japan C</option>
<option value="h.vodafone.ne.jp">Vodafone Japan H</option>
<option value="t.vodafone.ne.jp">Vodafone Japan T</option>
</select>
</div>
<input type="hidden" name="action" value="subscribe" />
<div style="display:none"><input type="text" name="VerificationCodeX" value="" size="20"></div>
<p>All of your info is kept secret and safe. Promise.</p>
</fieldset>
<div class="clear"></div>
<button type="submit" class="pure-button pure-button-primary"><i class="fa fa-pencil"></i> Subscribe </button>
<script language="Javascript">
$.verify.addRules({
cellphone: function(r) {
//pass validation if there is no carrier
if(!$("#carrier").val()) {
return true;
}
//perform cell validation here [Note: r.val() is a shortcut to $(element-being-validated).val() ]
if(/^\d{10}$/.test(r.val())) {
return "You must enter a valid cell-phone number";
}
//passed
return true;
}
});
</script>
</form>
<h1>Show Alert <i class="fa fa-bullhorn"></i></h1><br />
<h2>Never miss a show.</h2><br />
<h2 class="indent">Never miss the latest.</h2>
</div>
</div>
from verifyjs.
Related Issues (20)
- verification success handler HOT 4
- Empty error message for "required" rule HOT 1
- it works, but hides the form?
- Validation deletes pressed button from the POST request HOT 1
- i18n
- How to make validation message appear next to "Submit" button? HOT 1
- Cannot use `$.verify.updateRules`
- Validate on select
- problem wiith angularjs on submit
- specify custom error message as an attribute HOT 2
- wrong rule name
- Is it possible to add conditional verification HOT 4
- Link for new issues is dead at http://verifyjs.com/#contributing
- Have a "debug" / "Troubleshooting" section of the documentation.
- Causes two submits
- The 'scroll' option is not working
- Website is down, unable to find docs. HOT 2
- Successor project HOT 1
- Add option for timeout value
- Verifyjs for react
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from verifyjs.