none
[URGENT]Textbox issue RRS feed

  • Question

  • how to validate the textbox value in below format and store in the sharepoint list using Angular js scripting

    Snumber: 2-xx-xxx-xxxx


    Blitz


    • Edited by sree_23 Thursday, November 28, 2019 8:10 AM
    Thursday, November 28, 2019 7:07 AM

Answers

  • Hi,

    The following example code for your reference.

    <!DOCTYPE html>
    <html>
    <head>
    	<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script>
    	<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.4/angular-messages.min.js"></script>
    	<script>
    	var app = angular.module('app', ['ngMessages']);
    	</script>
    	<style>
    	.error-message {
    		color:red;
    	}
    	</style>
    </head>
    <body ng-app="app">
    	<form name="exampleForm">
    		<input type="text" name="snumber" ng-model="snumber" ng-pattern="/^2-[0-9]{2}-[0-9]{3}-[0-9]{4}$/" ng-blur="formats(snumber)" ng-class="{'invalid format':sclassvalue=='invalid','valid'sclassvalue=='valid'}"  maxlength="15"/>	 
    		<div ng-messages="exampleForm.snumber.$error">       
    			<div class="error-message" ng-message="pattern">Please input a text in format 2-xx-xxx-xxxx.</div>
    		</div>   
    	</form>
    </body>
    </html>

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    • Marked as answer by sree_23 Friday, November 29, 2019 12:03 PM
    Friday, November 29, 2019 4:52 AM
    Moderator

All replies

  • Can you please elaborate your issue or requirement? By 'textbox', do you mean multi-line textbox? or Do you want to validate whether the number is in the format (2-xx-xxx-xxxx) as you have mentioned? Also, will the number always begin with 2?


    Please remember to up-vote & mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    • Edited by HarshalGite Thursday, November 28, 2019 8:56 AM
    Thursday, November 28, 2019 8:54 AM
  • yes its textbox control and its not multiline .yes it should be begin by 2 always and follow this format(2-xx-xxx-xxxx)  .im using HTML using Angular js script for this



    Blitz

    Thursday, November 28, 2019 11:13 AM
  • You can use regular expressions to match your text from input. Check the code below.

    var regex = /2-[a-zA-Z0-9]{2}-[a-zA-Z0-9]{3}-[a-zA-Z0-9]{4}/
    var textValue = document.getElementById('elementID').value;
    
    if(!textValue.match(regex)){
        alert("Not in the format-> 2-xx-xxx-xxxx");
    }
    else{
        alert("In correct format-> 2-xx-xxx-xxxx");
    }


    Please remember to up-vote & mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Thursday, November 28, 2019 11:54 AM
  • Hi,

    The following example code for your reference.

    <!DOCTYPE html>
    <html>
    <head>
    	<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script>
    	<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.4/angular-messages.min.js"></script>
    	<script>
    	var app = angular.module('app', ['ngMessages']);
    	</script>
    	<style>
    	.error-message {
    		color:red;
    	}
    	</style>
    </head>
    <body ng-app="app">
    	<form name="exampleForm">
    		<input type="text" name="snumber" ng-model="snumber" ng-pattern="/^2-[0-9]{2}-[0-9]{3}-[0-9]{4}$/" ng-blur="formats(snumber)" ng-class="{'invalid format':sclassvalue=='invalid','valid'sclassvalue=='valid'}"  maxlength="15"/>	 
    		<div ng-messages="exampleForm.snumber.$error">       
    			<div class="error-message" ng-message="pattern">Please input a text in format 2-xx-xxx-xxxx.</div>
    		</div>   
    	</form>
    </body>
    </html>

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    • Marked as answer by sree_23 Friday, November 29, 2019 12:03 PM
    Friday, November 29, 2019 4:52 AM
    Moderator