0

On my SharePoint online site I have a custom list with a Number field.I want to apply validation on this field so that the Number should not be less than or greater than 5 digits and it should be without commas and any wild characters.

2

You can use input mask on that number field.

Below is the script:

<script language="javascript" src="http://code.jquery.com/jquery-1.4.2.min.js" type="text/javascript" ></script>
<script language="javascript" src="http://jquery-joshbush.googlecode.com/files/jquery.maskedinput-1.2.2.min.js" type="text/javascript" ></script>
<script language="javascript" type="text/javascript">
jQuery(function($){
   $("input[title='Phone']").mask("(999) 999-9999? Ext.99999");
});
</script>

For your requirement, you can replace with below line:

$("input[title='NumberFieldName']").mask("99999");

Here is similar thread: Column validation for US phone number format

Reference: Input mask on textbox

1

Expanding on @Naveen's answer, for making the user only enter 5 digits you can enter this formula in column validation: =AND(Column>10000,Column<99999). You can then enter a custom message for that. Replace Column with your column name. As for the 2nd part of your question, since it's a number field it won't let you enter commas or wildcard entries.

0

You don't need to put any validations formula just define the lowest i.e 10000 and highest 99999 number. It will automatically restrict the special character in the field.

Done!!

  • I want to limit user to type only five digits for a better usability experience. – Jenny Aug 7 '15 at 8:42
  • You wish to add only five digits in the field and without prompting status message as in case input is greater than 5 digit it should be trimmed to 5 right? – Shivendra Patel Aug 7 '15 at 9:05
  • Yes that's exactly what i needed. Is there any solution without programming? I am not very good in programming. – Jenny Aug 10 '15 at 6:57
0

Go to "List Settings". Click on your Number field. Under "Additional Column Settings" specify the minimum and maximum values as 10000 and 99999 respectively.

enter image description here

With respect to comma, SharePoint puts a comma where appropriate. So a number 43000 would be displayed as 43,000. As for wildcard characters as it is a Number field it won't allow them to be save to List.

  • I want to limit user to type only five digits for a better usability experience. The user should be able to type only 5 digits at first place instead of having this weird message while saving the item (The value of this field must be between 10,000.00000 and 99,999.00000.) – Jenny Aug 7 '15 at 8:51
  • @Jenny: For "user should be able to type only 5 digits", you will have to look into JSLink. In SharePoint Online, in SharePoint Admin Center you need to enable "Custom Script" options to "Allow" for JSLink to be activated. Or you can do custom development using Visual Studio. Regarding the error message The value of this field must be between 10,000.00000 and 99,999.00000., you can trim those extra decimals by setting the "Number of decimal places" to '0' as shown in my answer's screenshot. – Naveen Aug 7 '15 at 9:14
  • @Jenny: Also, even if you set the maxlength for Number field to 5 (either using JSLink/Visual Studio), there's nothing to stop user's from entering values less than 5 characters in the field. So they would still receive the error The value of this field must be between 10,000.00000 and 99,999.00000. :) – Naveen Aug 7 '15 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.