It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.
...
//some code
var characterReg = /^([a-zA-Z0-9]{2,50})$/; //only letters and numbers
if ( !characterReg.test(inputValName) ){
result.text('that\'s not a valid name!');
...
//more code
function IsValidNIF(nif)
{
var c;
var checkDigit = 0;
//Check if is not null, is numeric and if has 9 numbers
if(nif != null && IsNumeric(nif) && nif.length == 9)
{
//Get the first number of NIF
c = nif.charAt(0);
//Check firt number is (1, 2, 5, 6, 8 or 9)
if(c == ‘1' || c == ‘2' || c == ‘5' || c == ‘6' || c == ‘8' || c == ‘9')
{
//Perform CheckDigit calculations
checkDigit = c * 9;
var i = 0;
for(i = 2; i <= 8; i++)
{
checkDigit += nif.charAt(i-1) * (10-i);
}
checkDigit = 11 - (checkDigit % 11);
//if checkDigit is higher than ten set it to zero
if(checkDigit >= 10)
checkDigit = 0;
//Compare checkDigit with the last number of NIF
//If equal the NIF is Valid.
if(checkDigit == nif.charAt(8))
return true;
}
}
return false;
}
function IsNumeric(ObjVal)
{
return /^\d+$/.test(ObjVal);
}
...
//some code
var myRegex = /^[125689][0-9]{8}$/;
if ( myRegex.test(inputValName) ){
// then implement other if here with the modulo% code??
...
//more code
String.prototype.ozo = function(i) { return this.charAt(i-1) * (10-i); }
function IsValidNIF(nif) {
var checkDigit = 0;
for(var i=1;i<9;i++) checkDigit += nif.ozo(i);
return /^[125689][0-9]{8}$/.test(nif) && ((checkDigit%11 >= 21)?0:checkDigit == nif.charAt(8));
}
<script>
function clearInput() {
$("#myForm :input").each( function() {
$(this).val('');
});
};
$("#submitBtn").click( function() {
var result = $('#result');
var company = $('#myForm > #name-of-company');
var ai = $('#myForm > #annual-income');
var characterReg = /^([a-zA-Z0-9]{2,50})$/; //only letters and numbers
var aiReg = /^([0-9]{3,15})$/; //only numbers
var inputVal = ai.val();
var inputValName = company.val();
if ( !characterReg.test(inputValName) ){
result.text('that\'s not a valid name!');
company.addClass('wrong');
} else if ( !aiReg.test(inputVal) ) {
result.text('only numbers!');
ai.addClass('wrong');
company.removeClass('wrong');
} else {
$.post( $("#myForm").attr("action"),
$("#myForm :input").serializeArray(),
function(info){ result.html(info);
});
clearInput();
company.removeClass('wrong');
ai.removeClass('wrong');
};
});
$("#myForm").submit( function() {
return false;
});
</script>
function IsValidNIF(nif)
{
var checkDigit = 0;
var i = 0;
var characterReg = /^[125689][0-9]{8}$/;
if (characterReg.test(nif) {
//Perform CheckDigit calculations
checkDigit = nif.charAt(0) * 9;
for(i = 2; i <= 8; i++)
{
checkDigit += nif.charAt(i-1) * (10-i);
}
checkDigit = 11 - (checkDigit % 11);
//if checkDigit is higher than ten set it to zero
if(checkDigit >= 10)
checkDigit = 0;
//Compare checkDigit with the last number of NIF
//If equal the NIF is Valid.
if(checkDigit == nif.charAt(8))
return true;
}
return false;
}
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.
-must be 9 characters(numbers) long
-the first number must be 1 or 2 or 5 or 6 or 8 or 9
characterReg = /^[125689][0-9]{8}$/
-the last number performs some validation(%module) that you should understand viewing the above code
This part would produce a more complicated regular expression than is worth it, so I'd stick to using code.