Help with validating data entered in Masked Input control

Hi

How do i modify this script to make sure all required data is entered, currently when i enter a number at the end of the masked input control, for example +__9, the invalid error message does not activate.

 function C1FTL_OnClientBlur(sender, e) {

                var mskinput = $find('<%=C1FTL.ClientID%>');
                var txb = $('#C1FTL_C1TextBox');
                if (mskinput.get_text().trimEnd().length < 4 && mskinput.get_text().trimEnd().length > 0) {
                    alert("Invalid");
                    document.focus();
                    mskinput.focus();

                }

            };

            function C1FTL_OnClientFocus(sender, e) {

                var text = document.getElementById("C1FTL_C1TextBox");
                var txb = $('#C1FTL_C1TextBox');
                var FieldRange = text.createTextRange();
                FieldRange.moveStart('character', 0);
                FieldRange.collapse();
                FieldRange.select();

            };

<cc2:C1MaskedInput ID="C1FTL" runat="server" Mask="&amp;999" Width="30px"
                         style="top: 0px; left: 0px" OnClientBlur="C1FTL_OnClientBlur"
                         OnClientFocus="C1FTL_OnClientFocus"  />

Thanks,

Victor
vcharlesAsked:
Who is Participating?
 
Obadiah ChristopherConnect With a Mentor Commented:
if (mskinput.get_element().value.match(numbers)) {

Open in new window


Or I guess as used above should be used again
if (mskinput.get_text().value.match(numbers)) {

Open in new window

0
 
sivagnanam chandrakanthTechnical LeadCommented:
in your validation you have checked the length less than 4 characters, so the example "+__9" has 4 characters thats why its skipping the condition and error alert is not shown..
0
 
vcharlesAuthor Commented:
The __ represents space, no data was entered, it should have been +439, the masked control is &999 where 9 only allows numerical values. How do i make sure all three required numerical values are entered?
Thanks.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
sivagnanam chandrakanthTechnical LeadCommented:
Use this, this will take care of all your need with masked input

http://digitalbush.com/projects/masked-input-plugin/
0
 
vcharlesAuthor Commented:
Unfortunately, I am not allowed to use additional controls/plugins in this project. Is there a way for the script to look for number of numerical values and if not = 3 activate the alert?
0
 
sivagnanam chandrakanthTechnical LeadCommented:
Yes use ASCII code validation or regular expression validation or ISNAN for individual characters by splitting the values

R.E http://www.w3resource.com/javascript/form/all-numbers.php
0
 
vcharlesAuthor Commented:
Thanks. Using Javascript below, since I only need three digits, would using var numbers = /^[0-3]+$/;  work? It seems like that part of the code is just to make sure numeric values are entered, don't see where it is testing for number of numeric values entered.


function allnumeric(inputtxt)  
      {  
      var numbers = /^[0-9]+$/;  
      if(inputtxt.value.match(numbers))  
      {  
      alert('Your Registration number has accepted....');  
      document.form1.text1.focus();  
      return true;  
      }  
      else  
      {  
      alert('Please input numeric characters only');  
      document.form1.text1.focus();  
      return false;  
      }  
      }
0
 
sivagnanam chandrakanthTechnical LeadCommented:
yes it is checking only the numeric value not length..

Add this for length

 if(inputtxt.length>3)  
      {  
      alert('Max 3 didgits only');  
      document.form1.text1.focus();  
      return true;  
      }
0
 
vcharlesAuthor Commented:
Thanks, but still not clear on how to use this code in my project, below is the code I currently have

function C1FTL_OnClientBlur(sender, e) {

                var mskinput = $find('<%=C1FTL.ClientID%>');
                var txb = $('#C1FTL_C1TextBox');
                if (mskinput.get_text().trimEnd().length < 4 && mskinput.get_text().trimEnd().length > 0) {
                    alert("Invalid");
                    document.focus();
                    mskinput.focus();

                }

            };


How would you integrate your code to check for the length of numeric values entered?
I don't understand how does how inputtxt would be recognized in the code above?

function allnumeric(inputtxt)  
      {  
      var numbers = /^[0-9]+$/;  
  if(inputtxt.length>3)  
      {  
      alert('Max 3 didgits only');  
      document.form1.text1.focus();  
      return true;  
      }
0
 
sivagnanam chandrakanthTechnical LeadCommented:
Try this

function C1FTL_OnClientBlur(sender, e) {

                var mskinput = $find('<%=C1FTL.ClientID%>');
                var txb = $('#C1FTL_C1TextBox');
                if (mskinput.get_text().trimEnd().length > 3 && mskinput.get_text().trimEnd().length > 0) {
                    alert("Maximum 3 digits only");
                    document.focus();
                    mskinput.focus();

                }
				var numbers = /^[0-9]+$/;   
      if(mskinput.value.match(numbers))   
      {   
      alert('Your Registration number has accepted....');   
      
      return true;   
      }   else{
		  alert('Please input numeric characters only');   		  
		  return false;   
	  }

            };
			
			
	

Open in new window

0
 
vcharlesAuthor Commented:
I am getting error message:

Microsoft JScript runtime error: 'value' is null or not an object

On line:  if (mskinput.value.match(numbers)) {


Code:

function C1FTL_OnClientBlur(sender, e) {

                var mskinput = $find('<%=C1FTL.ClientID%>');
                var txb = $('#C1FTL_C1TextBox');
                if (mskinput.get_text().trimEnd().length < 3 && mskinput.get_text().trimEnd().length > 0) {
                    alert("3 digits Required");
                    document.focus();
                    mskinput.focus();

                }
                var numbers = /^[0-9]+$/;
                if (mskinput.value.match(numbers)) {
                    alert('Your Registration number has accepted....');

                    return true;
                } else {
                    alert('Please input numeric characters only');
                    return false;
                }

            };
0
 
sivagnanam chandrakanthTechnical LeadCommented:
Are you sure mskinput has input field value?
0
 
vcharlesAuthor Commented:
Yes data is in the  c1ftl Lasker Input control
0
 
vcharlesAuthor Commented:
I tried the code below but the invalid alert does not triggre when I enter less than three digits.

 function C1FTL_OnClientBlur(sender, e) {

                var mskinput = $find('<%=C1FTL.ClientID%>');
                var txb = $('#C1FTL_C1TextBox');
                if (mskinput.get_text().trimEnd().length < 3 && mskinput.get_text().trimEnd().length > 0) {
                    alert("Maximum 3 digits only");
                    document.focus();
                    mskinput.focus();

                }
                var numbers = /^[0-9]+$/;
                if (mskinput.get_text().trimEnd().length = 3 && mskinput.get_text().trimEnd().length > 0) {
                    alert('Data accepted....');

                    return true;
                } else {
                    alert('Maximum 3 digits only');
                    return false;
                }

            };
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.