Question

I have a single line of text column in my list called "Invoice Number" which only needs to contain numeric characters (0-9).

I have attempted using column validation with =ISNUMBER([Invoice Number]+0)

However using this formula still allows for the use of symbols. As long as there is at least 1 number in the text box it will allow you to save the item with the following symbols - . + £ $

everything I have found online suggests using the formula above but is there anyway to tweak this formula to prevent the use of these symbols?

Was it helpful?

Solution

Two solutions come to mind...

Check for the problem characters:

=AND(
     ISNUMBER(0+[Invoice Number]),
     ISERR(FIND("$",[Invoice Number])),
     ISERR(FIND(".",[Invoice Number])),
     ISERR(FIND(",",[Invoice Number]))
    )

If the invoice number is a known length, check for the valid characters. This checks the first four characters:

=NOT(OR(
        ISERR(FIND(MID([Invoice Number],1,1),"0123456789")),
        ISERR(FIND(MID([Invoice Number],2,1),"0123456789")),
        ISERR(FIND(MID([Invoice Number],2,1),"0123456789")),
        ISERR(FIND(MID([Invoice Number],4,1),"0123456789"))
     ))

Regular Expressions would be a real nice addition to SharePoint formulas!

OTHER TIPS

Why haven't you used Number column? You can have min and max value set to 0 - 9 there. SharePoint will validate it by default.

Add this code to a Code Editor Web Part below the list form in your NewForm or EditForm:

[javascript]
<script type="text/javascript" src="/test/English/Javascript/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
fields = init_fields_v2();

// Allow numbers only in text fields
// Array of FieldInternalNames to lilmit to numbers only
var arrToCheckForNum = [‘Title’,’Num’];
// Array of length of input string – set to 255 if you do not want to limit input length. Corresponds to the same array index in the "arrToCheckForNum"
var lengthOfInputNumber = [9,2];

$.each(arrToCheckForNum,function(idx,item){
$(fields[item]).find(‘input’).css({‘width’:’75px’});
$(fields[item]).find(‘input’).keyup(function(e){
var thisVal = $(this).val();
thisVal = thisVal.substring(0,lengthOfInputNumber[idx]);
$(this).val(thisVal.replace(/[^0-9]/g,”));
}).blur(function(){
var thisVal = $(this).val();
thisVal = thisVal.substring(0,lengthOfInputNumber[idx]);
$(this).val(thisVal.replace(/[^0-9]/g,”));
});
});

/*
LastMod: 07.05.2010
*/
function init_fields_v2(){
var res = {};
$("td.ms-formbody").each(function(){
var myMatch = $(this).html().match(/FieldName="(.+)"s+FieldInternalName="(.+)"s+FieldType="(.+)"s+/);
if(myMatch!=null){
// Display name
var disp = myMatch[1];
// FieldInternalName
var fin = myMatch[2];
// FieldType
var type = myMatch[3];
if(type==’SPFieldNote’){
if($(this).find(‘script’).length>0){
type=type+"_HTML";
}
}
if(type==’SPFieldLookup’){
if($(this).find(‘input’).length>0){
type=type+"_Input";
}
}
// Build object
res[fin] = this.parentNode;
res[fin].FieldDispName = disp;
res[fin].FieldType = type;
}
});
return res;
}
</script>
[/javascript]

The parameters “arrToCheckForNum” and “lengthOfInputNumber” must be changed depending on your needs.

The jQuery-library is found here. The pictures and the sourcecode refers to jquery-1.4.2.min. If you use another version, remember to update the script “src”.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top