Currently i am using the following script to check if my field is empty or not. For me this script works great, the only thing I want to add to the script is a check that the field needs at least 10 digits (numbers) in it too otherwise just shows the error message as in the script. I hope someone can help me find out what needs to be added to the code below

```
function checkforblank() {
var errormessage = "";
if (document.getElementById('telefoonnummer').value == "") {
errormessage += "your 10 digits phone number is missing " ;
document.getElementById('telefoonnummer').style.bordercolor = "red";
}
if (errormessage != "") {
$(".error-messages").text(errormessage).fadeIn();
return false;
}
}
```

Remove all non-digits and take the length

```
'a0b123c456v789---'
.replace(/[^\d]/g, '') // "0123456789"
.length; // 10
```

```
//this is to check weather it is a number or not------
function checkNumber(event,val){//use this function at keyup event of your field
if(val.length <= 10) //check wether it is 10 digit or not
{
if ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 || event.keyCode == 13 ||
// Allow: Ctrl+A
(event.keyCode == 65 && event.ctrlKey === true) ||
// Allow: home, end, left, right
(event.keyCode >= 35 && event.keyCode <= 39)) {
// let it happen, don't do anything
return;
}
else {
// Ensure that it is a number and stop the keypress
if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105 )) {
event.preventDefault();
}
}
}
}
```

use the code with the your text field like this

```
<input type="text" id="phone" onkeyup = "checkNumber(event,this.value);" />
```

If all you need is a plain length check on submit and the field can have only digits, you can use the below to check for length.

```
function checkforblank() {
var errormessage = "";
var inputVal = document.getElementById('telefoonnummer').value;
if (inputVal == "") {
errormessage += "your 10 digits phone number is missing " ;
document.getElementById('telefoonnummer').style.bordercolor = "red";
}
else if (inputVal != "" && inputVal.length !== 10) {
console.log("error");
//set your error message here
}
else {
console.log("success");
}
if (errormessage != "") {
$(".error-messages").text(errormessage).fadeIn();
return false;
}
}
```

**Update**: Revised Version based on OP feedback - fiddle

Similar Questions

1)I need to check if String contains a String characters what will be the corect way how to do it ? 2) Are some ways how to corectly transform String to number and then compare theese two number s? L

I need to count the number of decimal digits in a number(for ex: 4 for 1002). I want to do this in O(1) time complexity as the code shall be iterated over huge set of numbers, significantly saving cpu

This question already has an answer here: Formatting the phone number 2 answers I am trying to format a telephone number field in CRM 2011, but only if the field contains 10 digits. Some of the

I need to break down a binary number into 4 decimal digits using assembly. For example, break down 0010 0110 1001 0010 which is 9874 into '9' '8' '7' '4' and show each on a 7-segment display. I got th

I want such a validation that My String must be contains at least one alphabet. I am using the following: String s = 111a11; boolean flag = s.matches(%[a-zA-Z]%); flag gives me false even though

I want to check if a string contains only digits. I used this: var isANumber = isNaN(theValue) === false; if (isANumber){ .. } .. but realized that it also allows + and -. Basically I wanna make sure

I am trying to see whether a string contains at least a digit or a lowercase or an uppercase. I have written something like this: int combinations = 0; string pass = !!!AAabas1; if (pass.matches([

How to check tgat a generated string contains at least one letter using php. Can someone help me?

Is there a way to limit number of digits in integer in OpenERP like you can in char type? I need field that would only let you enter max two digits. For example with char, you can do this: from opener

I have numbers like 1100, 1002, 1022 etc. I would like to have the individual digits, for example for the first number 1100 I want to have 1, 1, 0, 0. How can I get it in Java?

I'm trying to generate two random digits (numbers 0-9) in my Actionscript/Flash game. However, they must add up to at least 10 (that's part of the game, otherwise the game would be pointless, I can ex

Is the query correct if I wanted to check if the field has other characters other than null and empty? select CASE WHEN description IS NULL THEN 'null' WHEN description IS NOT NULL THEN 'not null' ELS

This question already has an answer here: Zero-pad digits in string 3 answers Formatting a number with leading zeros in PHP 7 answers For example, I have this format: $s_number = 12; And

it's been a long day and I think I just have code blindness but.. Trying to figure out if an element contains a number, do something to another element. result_val = 9; $(.result).contains(+result_

How can I remove a certain number of digits in a number so the number obtained is minimal? Specifically, I want to write a function int remove_digits(int large, int num_digits_to_remove) such that: A

Let us say we have the following number. Number = 2001000200030 How can I grab the first digit and store it to a variable? Then grab the next four digits and store them to another variable? Then the

I try to use the following expression to check whether the password is a combination of number and letter despite the order of letter and number password.matches([a-zA-z]{1,}[0-9]{1,}) but the abov

Sometimes my document has a field that has null values. How do I check whether the value inside a field is a null string? How do I iterate through all documents and delete the field of the document

This question already has an answer here: Format string to a 3 digit number 4 answers I want to convert a number to a string but have the number formatted with 10 digits. For example, if the nu

I want to generate random number, which is 9 digits including leading zero if the number is less than 9 digits, say 123 will be 000000123. I have the following code which doesn't include leading zero

I simply want to check if the input from field and field1 is the same. but I'm not sure where my mistake is. jQuery Code: $(document).ready(function () { $('#f').validate({ rules: { field: { nowhites

how could I check programmatically whether a NSFont contains a unicode character like '°'?

I have a Dictionary private readonly Dictionary<int, BinaryAssetExtensionDto> _identityMap; And I would like to do something like this: if(_identityMap.Values.Contains(x => x.extension == ex

In HTML we have a number like 12.34 When someone hovers their mouse over it I'd like it to expand with some sort of transition to reveal additional significant digits, for example 12.345678. Is this p

I have three textboxes on an asp.net webform, how/can I use a required field validator to ensure that at least one of them contains text?

I need to create a datatype, which supports numbers with at least x digits and be able to store also more than x digits. In TCPE the datatype is called NUM(m[,n]). M means an unsigned numeric value wi

Is it possible to modify the standard Numeric Format G so that the exponent is used when the number contains more than 2 zeros after the decimal place. If not, alternative solutions will be apprecia

Possible Duplicate: How can I create a Zerofilled value using JavaScript? I have to output a day number that must always have 3 digits. Instead of 3 it must write 003, instead of 12 it must write 01

I need to format double type so that it has minimum two decimal digits but without limitation for maximum number of decimal digits: 5 -> 5.00 5.5 -> 5.50 5.55 -> 5.55 5.555 -> 5.555

I wish to check if a password contains at least one letter and a number. special characters are accepted but not required... That will be a simple password checker.

This question already has an answer here: Way to get number of digits in an int? 15 answers I have do detect the amount of digits on a number. For example, 329586 has 6 digits. What I done, is

I'm trying to find the pure CSS solution that will render this layout using the least number of DOM elements and without any images. The real problem is getting a div to be 50% width minus some pixel

Is it possible to match an arbitrary number of digits with the php glob function? I'm trying to match file names for image thumbnails that end with dimensions ranging from two to four digits. I know

I have written a code in PLSQL. Where in I need to Check if sum of cubes of digits = to number itself. I have tried abiding by the algorithm,still there are some errors.Please help. I'm new to PLSQL.

I am trying to write a function in SML that takes an integer and outputs the number of digits int he number. For example, user inputs 122, I want to output 3. I thought this functions would do the tri

How can I check if a field exists?

How to check if there is at least: two letters, one number and one special character in java? Here is my code but I dont know if I'm in the right direction. public static boolean validarCodigo(String

I need to filter out only strings that contains only digits and/or a fix set of punctuation. I've tried checking each character and then summing the Boolean conditions to check if it is equal to the

In Java for String class there is a method called matches, how to use this method to check if my string is having only digits using regular expression. I tried with below examples, but both of them re

I was asked in an interview recently how would I write an algorithm to count the number of digits in a given number. So for example if I was given a number 500 the result would be 3. If I was given a

I have a table with following structure,in which first TD of each row contains a checkbox.I have a hidden field which contains comma separated values of second TD of rows whose check box has to be che

I have been searching for regular expression which accepts at least two digits and one special character and minimum password length is 8. So far I have done the following: [0-9a-zA-Z!@#$%0-9]*[!@#$%0

Is there a straightforward way of determining the number of decimal places in a(n) integer/double value in PHP? (that is, without using explode) Thanks, Erwin

I have a text column ( MISCDATA ) in a database wich contains multiple numeric values and string values, separated by comas and semicolons. Is there a way to build a query to select only the rows wher

I want to generate two different random numbers which has 15 digits. How can I do that Thanks

What is the fastest way to count the number of significant digits of a number? I have the following function, which works, but is quite slow due to string operations. /** * Count the number of signif

I know that radix sort works by comparing the digits of the numbers. My question is, assume we have different numbers with different number of digits. Does radix sort work here? We can simply assume t

How do I check if there are only two digits maximum in if(++$i > $_GET['number']) break; ?

Given a large number, e.g. 9223372036854775807 (Int64.MaxValue), what is the quickest way to sum the digits? Currently I am ToStringing and reparsing each char into an int: num.ToString().Sum(c =>

What is the simplest regular expression that will check if a string contains at least one uppercase letter and one lowercase? Edit: This is for a password where there may be numeric characters present