Discussions
Stay up-to-date with the latest news from NetSuite. You’ll be in the know about how to connect with peers and take your business to new heights at our virtual, in-person, on demand events, and much more.
Now is the time to ask your NetSuite-savvy friends and colleagues to join the NetSuite Support Community! Refer now! Click here to watch and learn more!
Stay in the Know
Be sure you're subscribed to NetSuite communication to stay in the know about monthly happenings, updates and announcements. Subscribe
Be sure you're subscribed to NetSuite communication to stay in the know about monthly happenings, updates and announcements. Subscribe
Kilimanjaro - how can we extend validation patterns
Hello! We use SuiteCommerce Advanced Kilimanjaro and I have a question regarding being able to extend the Backbone.Validation.patterns fields. Ultimately I would like to call a new pattern we're creating from within code as such; Backbone.Validation.patterns.customPattern.test(<string to test>).
In the third_parties directory there is the backbone-validation module that includes backbone-validation.js, which is where the base logic is for validation. In the suitecommerce/BackboneExtras module there's Backbone.Validation.patterns.js, which looks like it's an extension to the base .patterns object:
define('Backbone.Validation.patterns'
, [ 'Backbone'
, 'underscore'
, 'Backbone.Validation'
]
, function (
Backbone
, _
)
{
'use strict';
_.extend(Backbone.Validation.patterns,
{
// Same as email but is more restrictive and matches the same emails as the Netsuite backend UI
// Source: https://system.netsuite.com/javascript/NLUtil.jsp__NS_VER=2014.1.0&minver=154&locale=en_US.nlqs
// (Search for NLValidationUtil_SIMPLE_EMAIL_PATTERN)
email: /^[-a-z0-9!#$%&'*+/=?^_`{|}~]+(?:\.[-a-z0-9!#$%&'*+/=?^_`{|}~]+)*@(?:[a-z0-9]+(?:-+[a-z0-9]+)*\.)+(?:xn--[a-z0-9]+|[a-z]{2,16})$/i
//This validation is less restrictive than standard and matches with the used in Netsuite backend
, netsuiteUrl: /^(https|http|ftp|file):\/\//
, netsuiteFloat: /^-{0,1}([0-9])+(\.{1}[0-9]+)?$/
, netsuiteInteger: /^-{0,1}([0-9])+$/
//Allow numbers bettwen 000.00 and 000100.00 ending with optional %
, netsuitePercent: /^0*((([0-9]{1,2})(\.[0-9]{1,2})?%?$)|(100(\.0{1,2})?%?$))/
//Allow any character 7 or more times (this is the validation that the netsuite backend form does on phone type fields)
, netsuitePhone: /^.{7,}$/
});
return Backbone.Validation.patterns;
});
Tagged:
0