Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8044473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:14:29+00:00 2026-06-05T05:14:29+00:00

I am trying to verify that the format of a variable is a number

  • 0

I am trying to verify that the format of a variable is a number and is at least 10 digits long with leading zeros, inside of an expect script.

In a bash script it would look something like this:

[[ "$var" != +([0-9]) ]] && echo "bad input" && exit
while [[ $(echo -n ${var} | wc -c) -lt 10 ]] ; do var="0${var}" ; done

For the following input:

16

I am trying to achieve the following output:

0000000016

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T05:14:31+00:00Added an answer on June 5, 2026 at 5:14 am

    The simplest way to check whether a variable has just digits is to use a regular expression. Expect’s regular expressions are entirely up to the task:

    if {![regexp {^\d+$} $var]} {
        puts "bad input"
        exit
    }
    

    Padding with zeroes is best done by formatting the value; if you know C’s printf(), you’ll recognize the format:

    set var [format "%010d" $var]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a given string, I'm trying to verify that there are at least two
I'm trying to get it to verify that it has the same item in
I'm trying to use mock to verify that an index property has been set.
While trying to verify to myself, that C# Equals for IEnumerables is a reference
I'm trying to verify that an Account Name is not already in use once
I am trying to verify that a C# string is compliant with XML Schema
Currently I verify that there are no duplicated Members when trying to create a
I am trying to verify that my uitextfield, which only allows numbers isn't 0
I am trying to verify that my Rails code calls ActiveRecord's all method (all
I'm playing around with some unit tests and mocking. I'm trying to verify that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.