0

I have already set the maximum length, but now I need the user to enter not less than a certain amount

This is the script I'm using :

function PreSaveAction() {
var control = getElementByID("IBAN(24 Digits Alpha Numeric)");
 if(control.value.length < 24) 
 { 
  alert("The length in this field should not be less than 24 chars"); 
  return false; // Cancel the item save process 
 } 
else { return true ;}
}
  • Is this working for you or not? may be getElementByID is not returning anything. – Ganesh Sanap May 13 '19 at 7:26
  • @GaneshSanap No, this isn't working for me. And yes, I too think that getElementByID is not returning anything. What would be the correct way to get value from the input field? – Nyrmil Nanji May 13 '19 at 7:31
  • Try the solution given below. let me know if it works for you. – Ganesh Sanap May 13 '19 at 7:32
  • @GaneshSanap no it doesnt, since i get a word count/limit error. – Nyrmil Nanji May 13 '19 at 7:34
2

SharePoint OOTB Solution:

Use Column Validation:

  1. Go to your list settings.
  2. Click on your text column.
  3. Move to column validation section and enter below expression:

    =LEN([your column name])>24

And you can enter some message in user message section.

JavaScript Approach:

Try using below code:

Assuming the display name of your field is "IBAN(24 Digits Alpha Numeric)".

var control = document.querySelector("input[title^='IBAN(24 Digits Alpha Numeric)']");
| improve this answer | |
  • i have already used column validation for something else, so when i add this line of code, it gives me a word count error :) – Nyrmil Nanji May 13 '19 at 7:33
  • Can you post the existing formula? so that we can merge the formula and see if it works. – Ganesh Sanap May 13 '19 at 7:34
  • =AND(IF(ISERROR(FIND(",",[IBAN(24 Digits Alpha Numeric)])),TRUE),IF(ISERROR(FIND("&",[IBAN(24 Digits Alpha Numeric)])),TRUE),IF(ISERROR(FIND("!",[IBAN(24 Digits Alpha Numeric)])),TRUE),IF(ISERROR(FIND("@",[IBAN(24 Digits Alpha Numeric)])),TRUE),IF(ISERROR(FIND("#",[IBAN(24 Digits Alpha Numeric)])),TRUE),IF(ISERROR(FIND("$",[IBAN(24 Digits Alpha Numeric)])),TRUE),IF(ISERROR(FIND("%",[IBAN(24 Digits Alpha Numeric)])),TRUE),IF(ISERROR(FIND("*",[IBAN(24 Digits Alpha Numeric)])),TRUE),IF(ISERROR(FIND("-",[IBAN(24 Digits Alpha Numeric)])),TRUE)) – Nyrmil Nanji May 13 '19 at 7:37
  • The text you entered for the Validation Formula must be 1024 characters or fewer, including the leading '=' character. – Nyrmil Nanji May 13 '19 at 7:39
  • Tried using the JavaScript approach but it does not work :( – Nyrmil Nanji May 13 '19 at 7:44
0

Please try below code to get the control element:

var control = WebForm_GetElementById("IBAN(24 Digits Alpha Numeric)");
| improve this answer | |

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.