Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Key validation */
- function isValidChar(e, rgex) {
- var evt = (e) ? e : window.event;
- var key = (evt.keyCode) ? evt.keyCode : evt.which;
- if (key != null) {
- key = String.fromCharCode(parseInt(key));
- var rx = new RegExp(rgex);
- return rx.test(key);
- }
- return true;
- }
- function testForValidCharacters(input, rgex) {
- var rx = new RegExp(rgex);
- var currentValue = $(input).val();
- if (currentValue != "") {
- if (!rx.test(currentValue)) {
- $(input).val("");
- $(input).change();
- }
- }
- }
- function isEmptyFloatValue(val) {
- return (val === undefined || val == null || val.length <= 0 ) ? "0" : val.replace(/\,/g, "");
- }
- /* end - Key validation */
- /* confirm dialog for delete */
- function confirmDialog(e, a, message) {
- e = $.event.fix(e);
- e.preventDefault();
- bootbox.confirm('Are you sure you want to ' + message + ' this record(s)', function (result) {
- if (result == true) {
- window.location.href = a.href;
- }
- });
- }
- /* end - confirm dialog for delete */
- /* accept numeric values and one period only */
- function amtOnly(elementRef) {
- var keyCodeEntered = (event.which) ? event.which : (window.event.keyCode) ? window.event.keyCode : -1;
- if ((keyCodeEntered >= 48) && (keyCodeEntered <= 57)) {
- return true;
- }
- else if (keyCodeEntered == 46) {
- if ((elementRef.value) && (elementRef.value.indexOf('.') >= 0))
- return false;
- else
- return true;
- }
- return false;
- }
- /* end: accept numeric values and one period only */
- /* accept numeric values only */
- function numericOnly(elementRef) {
- var keyCodeEntered = (event.which) ? event.which : (window.event.keyCode) ? window.event.keyCode : -1;
- if ((keyCodeEntered >= 48) && (keyCodeEntered <= 57)) {
- return true;
- }
- return false;
- }
- /* end: accept numeric values only */
- //jQuery functions
- if (window.jQuery) {
- /* All onload functions */
- $(document).ready(function () {
- // On keypress
- // $(".wholenum").keypress(function () { return isValidChar(event, '[0-9]'); })
- $(document.body).on('keypress', '.wholenum', function () { return isValidChar(event, '[0-9]'); });
- $(".currency").keypress(function () { return isValidChar(event, '[0-9.]'); })
- $(".currency2").keypress(function () { return isValidChar(event, '[0-9.-]'); })
- $(".currency3").keypress(function () { return isValidChar(event, '[0-9.]'); })
- // $(".nospec0").keypress(function () { return isValidChar(event, '[ a-zA-Z0-9]'); })
- $(".nospec1").keypress(function () { return isValidChar(event, '[ a-zA-Z0-9@,/&-]'); })
- $(".nospec2").keypress(function () { return isValidChar(event, '[ a-zA-Z0-9@,/]'); })
- $(".nospec3").keypress(function () { return isValidChar(event, '[ a-zA-Z0-9-]'); })
- $(".nospec4").keypress(function () { return isValidChar(event, '[ a-zA-Z@,/-]'); })
- $(".nospec5").keypress(function () { return isValidChar(event, '[ a-zA-Z0-9/-]'); })
- $(".nospec6").keypress(function () { return isValidChar(event, '[ a-zA-Z0-9,/-]'); })
- $(".nospec7").keypress(function () { return isValidChar(event, '[ a-zA-Z0-9.-]'); })
- $(".nospec8").keypress(function () { return isValidChar(event, '[ a-zA-Z0-9._@]'); })
- $(".nospec9").keypress(function () { return isValidChar(event, '[ a-zA-Z0-9.,/-]'); })
- $(".nospec10").keypress(function () { return isValidChar(event, '[ a-zA-Z0-9.,/@-]'); })
- //$(".nospecName").keypress(function () { return isValidChar(event, '[ a-zA-Z0-9\u00F1\u00D1!@#$%^&*();,.\'-]'); })
- //$(".nospecEmail").keypress(function () { return isValidChar(event, '[^ ,:;"\'/]'); })
- $(".seqno").keypress(function () { return isValidChar(event, '[0-9]'); })
- // On focus
- $(".currency").focus(function () { $(this).select(); })
- $(".currency2").focus(function () { $(this).select(); })
- $(".currency3").focus(function () { $(this).select(); })
- $(".searcher").focus(function () { SrchBxFocus(this); })
- // On blur or lose focus
- $(".currency").blur(function () { $(this).val(Currencify($(this).val())); })
- $(".currency2").blur(function () { $(this).val(Currencify($(this).val())); })
- $(".currency3").blur(function () { $(this).val(Currencify(noBelowZeroBalance($(this).val()))); })
- $(".shortdate").blur(function () { $(this).val(PadDate($(this).val())); $(this).change(); })
- $(".noForwardDate1521").blur(function () { $(this).val(PadDate($(this).val())); $(this).change(); })
- $(".noForwardDate1900").blur(function () { $(this).val(PadDate($(this).val())); $(this).change(); })
- $(".noForwardDate").blur(function () { $(this).val(PadDate($(this).val())); $(this).change(); })
- $(".noCurrentForwardDate").blur(function () { $(this).val(PadDate($(this).val())); $(this).change(); })
- $(".searcher").blur(function () { SrchBxBlur(this); })
- $(".currencySelect").focus(function () { return $(this).val($(this).val().replace(/\,/g, "")); $(this).change(); })
- $(".currencyDefaultValue").blur(function () { $(this).val(Currencify(isEmptyFloatValue($(this).val()))); $(this).change(); });
- //$(".required").change(function () { markAsRequried($(this), $(this).val()); });
- //$(".required").change(function () { toggleRequired($(this), $(this).val() == ""); });
- $(document.body).on('change', '.required', function () { toggleRequired($(this), $(this).val() == ""); });
- $(document.body).on('click', '.requiredRadio', function () { toggleRequired($(this), false); });
- $(document.body).on('keypress', '.nospecName', function () { return isValidChar(event, '[ a-zA-Z0-9\u00F1\u00D1!@#$%^&*()\\\\;,.\'-]'); });
- $(document.body).on('change', '.nospecName', function () { testForValidCharacters(this, '^[ a-zA-Z0-9\u00F1\u00D1!@#$%^&*()\\\\;,.\'-]*$'); });
- $(document.body).on('change', '.nospec0', function () { testForValidCharacters(this, '^[ a-zA-Z0-9]*$'); });
- $(document.body).on('keypress', '.nospec0', function () { return isValidChar(event, '[ a-zA-Z0-9]'); });
- $(document.body).on('change', '.wholenum', function () { testForValidCharacters(this, '^[0-9]*$'); });
- $(document.body).on('keypress', '.nospecEmail', function () { return isValidChar(event, '[^ ,:;"\'/]'); });
- $(document.body).on('keypress', '.nospecWebsite', function () { return isValidChar(event, '[a-zA-Z0-9-_/\\\\.]'); });
- $(document.body).on('change', '.nospecWebsite', function () { testForValidCharacters(this, '^[a-zA-Z0-9-_/\\\\.]*$'); });
- $(".shortdate").mask("99/99/9999", { placeholder: "mm/dd/yyyy" });
- $(".noForwardDate1521").mask("99/99/9999", { placeholder: "mm/dd/yyyy" });
- $(".noForwardDate1900").mask("99/99/9999", { placeholder: "mm/dd/yyyy" });
- $(".noCurrentForwardDate").mask("99/99/9999", { placeholder: "mm/dd/yyyy" });
- $(".noForwardDate").mask("99/99/9999", { placeholder: "mm/dd/yyyy" });
- //others
- // var s = $(".stickyDiv");
- // var pos = s.position();
- // $(window).scroll(function () {
- // var windowpos = $(window).scrollTop();
- // // s.html("Distance from top:" + pos.top + "<br />Scroll position: " + windowpos);
- // if (windowpos >= pos.top) {
- // s.addClass("stick");
- // } else {
- // s.removeClass("stick");
- // }
- // });
- })
- /* end - All onload functions */
- /* Datepicker & date formatter */
- //date formatter
- function PadDate(d) {
- var vDt = new Date(d);
- var ds = d.split("/");
- var dy = ds[2];
- var mm = vDt.getMonth() + 1;
- var dd = vDt.getDate();
- var yyyy = vDt.getFullYear();
- if ((ds.length == 3) && (dd <= 31) && (mm <= 12)) {
- //goto closest year
- if (dy.length < 4) {
- if (yyyy < 1940) { yyyy = yyyy + 100; }
- }
- //end
- if (mm < 10) { mm = '0' + mm; }
- if (dd < 10) { dd = '0' + dd; }
- var xdate = mm + '/' + dd + '/' + yyyy;
- return xdate
- }
- else { return ""; }
- }
- /* Number validators & formatters */
- function isValidNumba(c) { return !isNaN(parseFloat(c)) && isFinite(c) }
- function AmtListener(d) {
- d += "";
- x = d.split(".");
- x1 = x[0];
- x2 = x.length > 1 ? "." + x[1] : "";
- var c = /(\d+)(\d{3})/;
- while (c.test(x1)) {
- x1 = x1.replace(c, "$1,$2")
- }
- return x1 + x2
- }
- function Currencify(d) {
- var e = d.replace(/\,/g, "");
- if (isValidNumba(e)) {
- var c = parseFloat(e);
- nStr = c.toFixed(2);
- return AmtListener(nStr);
- }
- else { return ""; }
- }
- /* end - Number validators & formatters */
- //check jquery-ui
- if ($.ui) {
- //datepicker
- $(function () {
- $(".shortdate").datepicker({
- showAnim: "",
- changeMonth: true,
- changeYear: true,
- minDate: new Date(1900, 1, 1),
- yearRange: '1901:+75',
- dateFormat: "mm/dd/yy",
- onChangeMonthYear: function (year, month, day) {
- yearRange: '1901:+0',
- $(this).datepicker('setDate', new Date(year, month - 1, day.selectedDay));
- }
- });
- /* var vdisabled = $(".shortdate").attr('disabled');
- if (vdisabled == 'disabled') {
- $(".shortdate").datepicker('disable');
- }
- else {
- $(".shortdate").datepicker('enable');
- } */
- });
- $(function () {
- $(".noForwardDate1521").datepicker({
- showAnim: "",
- changeMonth: true,
- changeYear: true,
- yearRange: '1521:+0',
- dateFormat: "mm/dd/yy",
- maxDate: '0',
- minDate: new Date(1521, 1 - 1, 1),
- onChangeMonthYear: function (year, month, day) {
- yearRange: '1521:+0',
- $(this).datepicker('setDate', new Date(year, month - 1, day.selectedDay));
- }
- });
- });
- $(function () {
- $(".noForwardDate1900").datepicker({
- showAnim: "",
- changeMonth: true,
- changeYear: true,
- yearRange: '1900:+0',
- dateFormat: "mm/dd/yy",
- maxDate: '0',
- minDate: new Date(1900, 1 - 1, 1),
- onChangeMonthYear: function (year, month, day) {
- yearRange: '1900:+0',
- $(this).datepicker('setDate', new Date(year, month - 1, day.selectedDay));
- }
- });
- });
- $(function () {
- $(".noForwardDate").datepicker({
- showAnim: "",
- changeMonth: true,
- changeYear: true,
- yearRange: '1901:+0',
- dateFormat: "mm/dd/yy",
- maxDate: '0',
- minDate: new Date(1900, 1 - 1, 1),
- onChangeMonthYear: function (year, month, day) {
- yearRange: '1901:+0',
- $(this).datepicker('setDate', new Date(year, month - 1, day.selectedDay));
- }
- });
- /* var vdisabled = $(".shortdate").attr('disabled');
- if (vdisabled == 'disabled') {
- $(".shortdate").datepicker('disable');
- }
- else {
- $(".shortdate").datepicker('enable');
- } */
- });
- /* end - Datepicker & date formatter */
- $(function () {
- $(".noCurrentForwardDate").datepicker({
- showAnim: "",
- changeMonth: true,
- changeYear: true,
- yearRange: '1901:+0',
- dateFormat: "mm/dd/yy",
- maxDate: '-1',
- minDate: new Date(1900, 1 - 1, 1),
- onChangeMonthYear: function (year, month, day) {
- yearRange: '1901:+0',
- $(this).datepicker('setDate', new Date(year, month - 1, day.selectedDay));
- }
- });
- });
- $(function () {
- $(".defaultToday").datepicker('setDate', new Date());
- $(".defaultToday").change();
- });
- }
- }
- /* Added by Sir Eric - 07142014 */
- /* creation of alert message using pines notify */
- function showAlertMessage(message, type) {
- new PNotify({
- text: message,
- type: type,
- width: '1030px'
- });
- }
- /* end - creation of alert message using pines notify */
- function noBelowZeroBalance(d) {
- var x = ((isValidNumba(d)) ? d : 0).toString();
- return ((parseFloat(x) >= 0) ? d : 0).toString();
- }
- $(document).ready(function () {
- var prm = Sys.WebForms.PageRequestManager.getInstance();
- prm.add_initializeRequest(InitializeRequest);
- prm.add_endRequest(EndRequest);
- $(".shortdate").keypress(function () { return isValidChar(event, '[0-9/]'); })
- $(".noForwardDate1521").keypress(function () { return isValidChar(event, '[0-9/]'); })
- $(".noForwardDate1900").keypress(function () { return isValidChar(event, '[0-9/]'); })
- $(".noForwardDate").keypress(function () { return isValidChar(event, '[0-9/]'); })
- $(".numericTextbox").keypress(function () { return isValidChar(event, '[0-9]'); })
- $(".decimalTextbox").keypress(function () { return isValidChar(event, '[0-9.]'); })
- $(".shortdate").datepicker({});
- $(".noForwardDate1521").datepicker({ maxDate: '0' });
- $(".noForwardDate1900").datepicker({ maxDate: '0' });
- $(".noForwardDate").datepicker({maxDate: '0'});
- $(".noCurrentForwardDate").datepicker({maxDate: '-1'});
- });
- function InitializeRequest(sender, args) {
- }
- function EndRequest(sender, args) {
- $(".shortdate").keypress(function () { return isValidChar(event, '[0-9/]'); })
- $(".noForwardDate1521").keypress(function () { return isValidChar(event, '[0-9/]'); })
- $(".noForwardDate1900").keypress(function () { return isValidChar(event, '[0-9/]'); })
- $(".noForwardDate").keypress(function () { return isValidChar(event, '[0-9/]'); })
- $(".numericTextbox").keypress(function () { return isValidChar(event, '[0-9]'); })
- $(".decimalTextbox").keypress(function () { return isValidChar(event, '[0-9.]'); })
- $(".shortdate").datepicker({});
- $(".noForwardDate1521").datepicker({ maxDate: '0' });
- $(".noForwardDate1900").datepicker({ maxDate: '0' });
- $(".noForwardDate").datepicker({maxDate: '0'});
- $(".noCurrentForwardDate").datepicker({maxDate: '-1'});
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement