Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize input Verification judgment by JavaScript

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains the "JavaScript how to achieve input verification judgment", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "JavaScript how to achieve input verification judgment" bar!

The try statement enables you to test errors in a block of code.

The catch statement allows you to handle errors.

The throw statement allows you to create custom errors.

Finally enables you to execute code, after try and catch, regardless of the result.

The try statement allows you to define a block of code to detect errors at execution time.

The catch statement allows you to define a block of code to execute if an error occurs in the block of try code.

The JavaScript statements try and catch appear in pairs:

Try {

Blocks of code for testing

}

Catch (err) {

A block of code that handles errors

}

When an error occurs, JavaScript usually stops and generates an error message.

The technical term goes like this: JavaScript will throw an exception (throw an error).

JavaScript actually creates an Error object with two properties: name and message.

Throw statement

The throw statement allows you to create custom errors.

Technically you can throw an exception (throw an error).

The exception can be a JavaScript string, number, Boolean, or object:

Throw "Too big"; / / throw text

Throw 500; / / throw a number

If you use throw with try and catch, you can control the program flow and generate custom error messages.

Enter a validation case

This example checks the input. If the value is incorrect, an exception (err) is thrown.

The err is caught by the catch statement and displays a custom error message:

Please enter a number between 5 and 10:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report